Changes between Version 3 and Version 4 of LoggingBestPractice


Ignore:
Timestamp:
14/08/06 16:16:42 (13 years ago)
Author:
spascoe
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LoggingBestPractice

    v3 v4  
    3232{{{ 
    3333#!python 
    34 logging.basicConfig(level=logging.ERROR) 
     34root = logging.getLogger() 
     35rootHandler = logging.StreamHandler() 
     36rootHandler.setLevel(logging.ERROR) 
     37root.addHandler(rootHandler) 
    3538 
    3639csmlLogger = logging.getLogger('ndg.csml') 
     40csmlLogger.setLevel(logging.DEBUG) 
    3741csmlLogHandler = logging.FileHandler('./log/csml.log') 
    38 csmlLogHandler.setLevel(logging.DEBUG) 
    3942csmlLogger.addHandler(csmlLogHandler) 
     43 
     44csmlLogger.warn('Sent just to logfile') 
     45csmlLogger.error('Sent to stdout and logfile') 
    4046}}} 
    41 ~~This would log all messages from the ndg.csml package (and sub-packages) to "./log/csml.log" and also log all ERROR and CRITICAL messages to sys.stdout (i.e. ERROR/CRITICAL messages from ndg.csml get logged twice)~~. '''This is wrong: must check basicConfig semantics!''' 
     47This would log all messages from the ndg.csml package (and sub-packages) to "./log/csml.log" and also log all ERROR and CRITICAL messages to sys.stdout (i.e. ERROR/CRITICAL messages from ndg.csml get logged twice) 
     48 
     49Note that the logging level can be set on loggers or handlers, however in the instance above doing root.setLevel(logging.ERROR) would not have the desired effect because loggers will not filter messages that have been passed up the logger heirarchy.