Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default coloredlogs datetime output differs from standard formatter's behavior #16

Closed
e-yes opened this issue Mar 7, 2016 · 2 comments

Comments

@e-yes
Copy link

e-yes commented Mar 7, 2016

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.

@DeoLeung
Copy link

use

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

@xolox
Copy link
Owner

xolox commented Jul 15, 2017

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().

@xolox xolox closed this as completed Jul 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants