Changing decimal comma to point in logging asctime

For some years, I had been eying at the logging output of the following code:

FORMAT='%(asctime)s %(message)s'
logging.basicConfig(format=FORMAT, level='INFO')
logging.info('Comma, where is the point?')

It would produce:

2017-07-18 13:44:41,837 Comma, where is the point?

I am certain that the decimal mark was a full stop or period and it was to six decimals instead of just three, but somewhere in the line, it defaulted to comma.  It could conform to a standard, but I just find it too unusual to read, the comma catches my eyes every time I scan through.

Finally, I decided to look into how to change it back, and the following code does the job:

FORMAT='%(asctime)s.%(msecs)03d %(message)s'
logging.basicConfig(format=FORMAT, datefmt='%Y-%m-%d %H:%M:%S', level='INFO')

This only changes the decimal mark, the rest stays the same.  The datafmt argument is to change the asctime field format, but you need to use msecs field for the milliseconds.  If you like the timestamp with microseconds, just swap with 6 for six decimals.

Comments

Popular posts from this blog

Element-wise Operation on Iterables

Opening Note