Python Logging: Specifying converter attribute of a log formatter in config file

srimanthula.radhakrishna at gmail.com srimanthula.radhakrishna at gmail.com
Thu Aug 30 06:38:26 EDT 2012


I'd like to have all timestamps in my log file to be UTC timestamp. When specified through code, this is done as follows:

myHandler = logging.FileHandler('mylogfile.log', 'a')
formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)-15s:%(lineno)4s: %(message)-80s')
formatter.converter = time.gmtime

myLogger = logging.getLogger('MyApp')
myLogger.addHandler(myHandler)


I'd like to move away from the above 'in-code' configuration to a config file based mechanism.

Here's the config file section for the formatter:

[handler_MyLogHandler]
args=("mylogfile.log", "a",)
class=FileHandler
level=DEBUG
formatter=simpleFormatter

Now, how do I specify the converter attribute (time.gmtime) in the above section?



More information about the Python-list mailing list