Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25703
| From | David Bolen <db3l.net@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: logging time format millisecond precision decimalsign |
| Date | 2012-07-20 14:50 -0400 |
| Message-ID | <m2fw8m6zd7.fsf@valheru.db3l.homeip.net> (permalink) |
| References | <50095684$0$6957$e4fe514c@news2.news.xs4all.nl> |
"Alex van der Spek" <zdoor@xs4all.nl> writes:
> I use this formatter in logging:
>
> formatter = logging.Formatter(fmt='%(asctime)s \t %(name)s \t %(levelname)s
> \t %(message)s')
>
> Sample output:
>
> 2012-07-19 21:34:58,382 root INFO Removed - C:\Users\ZDoor\Documents
>
> The time stamp has millisecond precision but the decimal separator is a
> comma.
>
> Can I change the comma (,) into a period (.) and if so how?
I do it by:
1. Replacing the default date format string to exclude ms.
2. Including %(msecs)03d in the format string where appropriate. Using 'd'
instead of s truncates rather than shows the full float value.
So in your case, I believe that changing your formatter creation to:
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d \t %(name)s \t %(levelname)s \t %(message)s', '%Y-%m-%d %H:%M:%S')
should work. This uses the same date format as the default, but
without ms, though of course you could also opt to make any other date
format you prefer.
-- David
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
logging time format millisecond precision decimalsign "Alex van der Spek" <zdoor@xs4all.nl> - 2012-07-20 15:00 +0200 Re: logging time format millisecond precision decimalsign Peter Otten <__peter__@web.de> - 2012-07-20 16:31 +0200 Re: logging time format millisecond precision decimalsign David Bolen <db3l.net@gmail.com> - 2012-07-20 14:50 -0400
csiph-web