Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

475 views
Skip to first unread message

srimanthula....@gmail.com

unread,
Aug 30, 2012, 6:38:26 AM8/30/12
to
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?

bernhard....@gmail.com

unread,
Aug 30, 2012, 9:44:50 PM8/30/12
to
I have the same problem and couldn't find a solution. It seems that converters can only be set programmatically?

Vinay Sajip

unread,
Sep 16, 2012, 4:07:31 AM9/16/12
to
On Thursday, August 30, 2012 11:38:27 AM UTC+1, Radha Krishna Srimanthula wrote:
>
> Now, how do I specify the converter attribute (time.gmtime) in the above section?

Sadly, there is no way of doing this using the configuration file, other than having e.g. a

class UTCFormatter(logging.Formatter):
converter = time.gmtime

and then using a UTCFormatter in the configuration.

0 new messages