Python logger dynamic filename

Posted by sharjeel on Stack Overflow See other posts from Stack Overflow or by sharjeel
Published on 2010-05-02T16:37:19Z Indexed on 2010/05/02 16:48 UTC
Read the original article Hit count: 324

Filed under:
|

I want to configure my Python logger in such a way so that each instance of logger should log in a file having the same name as the name of the logger itself.

e.g.:

log_hm = logging.getLogger('healthmonitor')
log_hm.info("Testing Log") # Should log to /some/path/healthmonitor.log

log_sc = logging.getLogger('scripts')
log_sc.debug("Testing Scripts") # Should log to /some/path/scripts.log

log_cr = logging.getLogger('cron')
log_cr.info("Testing cron") # Should log to /some/path/cron.log

I want to keep it generic and dont want to hardcode all kind of logger names I can have. Is that possible?

© Stack Overflow or respective owner

Related posts about python

Related posts about logging