Tuesday, October 9, 2012

how to log each logger to individual files?



how to log each <named> logger to its own individual file?




python logging how to log to two separate log files?




1
http://stackoverflow.com/questions/5577637/python-logging-to-multiple-files


Here's an example:
import logging
logger1 = logging.getLogger('1')
logger1.addHandler(logging.FileHandler('/tmp/logger1'))
logger2 = logging.getLogger('2')
logger2.addHandler(logging.FileHandler('/tmp/logger2'))

logger1.error('1')
logger2.error('2')
Then,
 $ cat /tmp/logger1
 1
 $ cat /tmp/logger2
 2



addHandler a different file name to each logging.FileHandler('/the/filename') object.



Does someone has an example of logging in python to 2 or more different logfiles.
I want to log for example to '/tmp/foo.log' and '/tmp/bar.log'
Thanks in advance
T



2
http://stackoverflow.com/questions/2031394/python-logging-over-multiple-files

http://docs.python.org/release/2.7.1/library/logging.html













No comments:

Post a Comment