xolox/python-coloredlogs

Default coloredlogs datetime output differs from standard formatter's behavior

e-yes opened this issue · 2 comments

When I install coloredlogs formatter by
coloredlogs.install(level='DEBUG', fmt='%(asctime)s %(name)s %(levelname)s -- %(message)s')
(asctime)'s output loses milliseconds (which are very important for most of a projects.

2016-03-07 22:55:10,880 ScriptManager WARNING -- Bla-bla-bla
vs.
2016-03-07 22:55:35:16 ScriptManager WARNING -- Bla-bla-bla

It should be nice to have the same format logic as standard formatter has. I use coloredlogs as optional dependency and I expect the log output to look the same with or without it installed (except colors, of course;)).

BTW, is there any way to enable milliseconds? I tried to play with datefmt a bit, but couldn't figure out what to pass to it.

use

coloredlogs.install(level='DEBUG', fmt='%(asctime)s,%(msecs)d %(name)s %(levelname)s -- %(message)s')
xolox commented

Hi Alexey and thanks for the feedback.

Ever since release 0.1 of coloredlogs, milliseconds have never been a part of the default log format.

I do appreciate your point that milliseconds will be shown when logging.basicConfig() is called with its default arguments. However the goal of coloredlogs is to integrate tightly with Python's logging module, not to match all of its defaults.

But looking at the workaround suggested in this issue and reading through this StackOverflow discussion I find the workaround to be rather involved, which really shouldn't be necessary (it should be easier).

I've now released coloredlogs 7.1 which supports coloredlogs.install(milliseconds=True) to make it very easy to enable millisecond precision in timestamps (it's still not enabled by default though). I've also added a section to the online documentation which mentions that millisecond precision isn't enabled by default and explains how to enable it.

I'm going to close this issue now because I'm not going to change the default in coloredlogs but I do think I've made it very easy to enable compatibility with logging.basicConfig().