Logging Framework
Chandler uses the standard
Python logging framework. To control logging verbosity, rather than have have setLevel( ) calls sprinkled throughout the code, we will centralize the logging configuration to a single file, using Python's
config file format. By default we will have a logging config file named 'logging.conf' which will get loaded by default (with the root logger set a level 'WARNING'):
[loggers]
keys=root
[handlers]
keys=chandler_log
[formatters]
keys=form01
[logger_root]
level=WARNING
handlers=chandler_log
[handler_chandler_log]
class=FileHandler
level=NOTSET
formatter=form01
args=(os.path.join(PROFILEDIR,'chandler.log'), 'a')
[formatter_form01]
format=%(asctime)s %(name)s %(levelname)s: %(message)s
datefmt=
If you wish to make certain modules more verbose, create your own configuration file and tell Chandler (or headless.py) to use it via the '-L config.file' command line argument; you can also specify a config file's location via CHANDLERLOGCONFIG environment variable.
Each module that does logging should get a logger object as follows:
log = logging.getLogger(_ _ name _ _)
_ _ name _ _ will be automatically set by python to your module's full package name (such as 'osaf.framework.sharing.Sharing'). However, they should not include a logger.setLevel( ) call. If you want to increase the verbosity of a particular logger, copy logging.conf and edit it to suit your needs. For example, if I copy logging.conf to custom.conf and add entries for 'sharing' and 'cpia', I could tailor those to be 'INFO' and 'DEBUG':
[loggers]
keys=root,sharing,cpia
[handlers]
keys=chandler_log
[formatters]
keys=form01
[logger_root]
level=WARNING
handlers=chandler_log
[logger_sharing]
level=INFO
propagate=0
handlers=chandler_log
qualname=osaf.framework.sharing
[logger_cpia]
level=DEBUG
propagate=0
handlers=chandler_log
qualname=osaf.framework.blocks
[handler_chandler_log]
class=FileHandler
level=NOTSET
formatter=form01
args=(os.path.join(PROFILEDIR,'chandler.log'), 'a')
[formatter_form01]
format='%(asctime)s %(name)s %(levelname)s: %(message)s'
datefmt=
...and then tell Chandler or headless.py to use this config file via -L custom.conf . Please read the documentation about the
config file format; the gist of it is that if you want to tweak the verbosity level of a branch of the logger hierarchy you add a [logger_XXX] section and add XXX to '[loggers] keys=' at the top (no spaces). In the [logger_XXX] section, 'level=' is the verbosity level, 'propagate=0' says to not propagate messages up the hierarchy, 'handlers=chandler_log' says to use our log handler, and 'qualname=' specifies what part of our package space this logger controls. For example, 'qualname='osaf.framework' would tweak the verbosity of any module inside osaf.framework.
There is also a Test menu item that lets you choose a different log config file at runtime.