Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25694
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'root': 0.04; '"""': 0.05; 'method.': 0.05; 'attributes': 0.07; 'desired.': 0.07; 'hardcoded': 0.09; 'overridden': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'string)': 0.09; 'subclass': 0.09; 'def': 0.10; 'value.': 0.15; 'comma': 0.16; 'comma.': 0.16; 'message-id:@dough.gmane.org': 0.16; 'placeholder': 0.16; 'previously,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'started:': 0.16; 'url:py3k': 0.16; 'string': 0.17; 'wrote:': 0.17; 'alex': 0.17; 'instance': 0.17; 'string,': 0.17; 'url:dev': 0.17; '>>>': 0.18; 'import': 0.21; 'skip:% 10': 0.22; 'defined': 0.22; 'header:User-Agent:1': 0.26; 'logging': 0.27; 'change,': 0.27; 'header:X-Complaints-To:1': 0.28; 'appending': 0.29; 'coded': 0.29; 'decimal': 0.29; 'handled': 0.29; 'van': 0.29; 'url:python': 0.32; 'info': 0.32; 'skip:_ 30': 0.32; 'skip:l 40': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'version': 0.34; 'changed': 0.34; 'skip:l 30': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'does': 0.37; 'level': 0.37; '(for': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; '\xe2\x80\x93': 0.75; 'stamp': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: logging time format millisecond precision decimalsign |
| Date | Fri, 20 Jul 2012 16:31:52 +0200 |
| Organization | None |
| References | <50095684$0$6957$e4fe514c@news2.news.xs4all.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p5084baab.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2346.1342794732.4697.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1342794732 news.xs4all.nl 6920 [2001:888:2000:d::a6]:37416 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:25694 |
Show key headers only | View raw
Alex van der Spek wrote:
> 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 think you have to subclass Formatter.formatTime(). Here's a monkey-
patching session to get you started:
>>> import logging
>>> logging.basicConfig(format="%(asctime)s")
>>> logging.getLogger().error("foo")
2012-07-20 16:17:39,364
>>> _formatTime = logging.Formatter.formatTime
>>> def formatTime(*args):
... return _formatTime(*args).replace(",", ".")
...
>>> logging.Formatter.formatTime = formatTime
>>> logging.getLogger().error("foo")
2012-07-20 16:20:20.838
See also
http://docs.python.org/dev/py3k/library/logging.html#logging.Formatter.formatTime
"""
Changed in version 3.3: Previously, the default ISO 8601 format was hard-
coded as in this example: 2010-09-06 22:38:15,292 where the part before the
comma is handled by a strptime format string ('%Y-%m-%d %H:%M:%S'), and the
part after the comma is a millisecond value. Because strptime does not have
a format placeholder for milliseconds, the millisecond value is appended
using another format string, '%s,%03d' – and both of these format strings
have been hardcoded into this method. With the change, these strings are
defined as class-level attributes which can be overridden at the instance
level when desired. The names of the attributes are default_time_format (for
the strptime format string) and default_msec_format (for appending the
millisecond value).
"""
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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