Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pyloggingdirect [2014/10/26 01:52] (current)
Line 1: Line 1:
 +== Python Logging Example (no config file ==
  
 +<​code>​
 +#​!/​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)
 +</​code>​
 +
 +----
 +  * [[PythonInfo|Back to Python]] ​       ​
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