Overriding Logging Config FileHandler Filename

Kenneth Love klove at tax.ok.gov
Tue Sep 25 16:15:05 EDT 2007


I have a Python logging config file that contains a RotatingFileHandler
handler.  In the args key, I have hard-coded the log filename.  Everything
works great.

However, I find that I now need to override this filename at application
runtime.  Is there a good way to do this?

Here is a bit of sample code that (hopefully) clarifies my question.

--------------- log.ini -----------------
[loggers]
keys=root,processor

; Lots more stuff here: handlers, formatters, and loggers.......

[handlers]
keys=consoleHandler,fileHandler

[handler_fileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=standard
args=('D:\Projects\Python\src\log.log', 'a', 99999, 10)

-------------- mymain.py -----------------
import logging.config

logging.config.fileConfig('log.ini')

# TODO: Override log filename with new name (e.g. 'd:\\logs\\mymain.py.log')

log = logging.getLogger('mymain')

log.info('START: mymain.py')
log.info('FINISH: mymain.py')
------------------------------------------

adTHANKSvance,
Kenneth Love

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kenneth Love                   |         Oklahoma Tax Commission
DP Programmer/Analyst          |         Information Technology
(405) 522 - 5864               |         http://www.tax.ok.gov/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 





More information about the Python-list mailing list