Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Logging: Specifying converter attribute of a log formatter inconfig file

Reply
Thread Tools

Python Logging: Specifying converter attribute of a log formatter inconfig file

 
 
srimanthula.radhakrishna@gmail.com
Guest
Posts: n/a
 
      08-30-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?
 
Reply With Quote
 
 
 
 
bernhard.haslhofer@gmail.com
Guest
Posts: n/a
 
      08-31-2012
I have the same problem and couldn't find a solution. It seems that converters can only be set programmatically?



On Thursday, August 30, 2012 6:38:27 AM UTC-4, Radha Krishna Srimanthula wrote:
> 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?


 
Reply With Quote
 
 
 
 
Vinay Sajip
Guest
Posts: n/a
 
      09-16-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specifying two log files with one configuration file Peter Steele Python 1 01-09-2013 12:57 AM
Switching from XML formatter to Binary Formatter A.M-SG ASP .Net Web Services 1 11-22-2005 08:33 AM
Retreiving Parent Values by specifying a attribute value pathisunil@gmail.com XML 0 05-10-2005 04:50 PM
Specifying the src attribute on an IMG which is not on the server.. Rithish Javascript 2 05-11-2004 04:33 AM
Specifying string array as an attribute in HTML tag Jeff 'Jones' Putz ASP .Net Building Controls 0 07-28-2003 12:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57