Python Logging Example (no config file
#!/usr/bin/env python

import logging,logging.config
import random
import time
import sys

hh = logging.handlers.TimedRotatingFileHandler(filename='a.log', when='d', interval=1)
log = logging.getLogger('root')
log.addHandler(hh)
fmt = logging.Formatter('%(asctime)s %(message)s')
hh.setFormatter(fmt)
log.setLevel(logging.DEBUG)
for i in range(1000):
    try:
        log.debug('debug')
        log.info('info')
        log.warn('warn')
        log.error('error')
        log.fatal('fatal')
        time.sleep(random.randint(1,5))
    except:
        log.fatal("That's all folks!!!")
        sys.exit(1)

pyloggingdirect.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0