Milliseconds in logging format

Irmen de Jong irmen-NOSPAM- at xs4all.nl
Sun Jan 10 15:05:06 EST 2010


On 10-1-2010 20:04, Joan Miller wrote:
> How the logging '%(asctime)s' [1] specifier to gets the millisecond
> portion of the time if there is not a directive to get it from the
> time module [2] ?
>
>
> "The date format string follows the requirements of strftime()"
> [1] http://docs.python.org/library/logging.html#basic-example
>
> [2] http://docs.python.org/library/time.html#time.strftime

It appends them to the string that strftime() returned.
If you set a custom datefmt, it will stop doing this and you'll have to
use %(msecs) in your log format to get them back.

See the source, Lib/logging/__init__.py around line 400. (Python 2.6.4)

-irmen



More information about the Python-list mailing list