By default logging.Formatter('%(asctime)s')
prints with the following format:
2011-06-09 10:54:40,638
where 638 is the millisecond. I need to change the comma to a dot:
2011-06-09 10:54:40.638
To format the time I can use:
logging.Formatter(fmt='%(asctime)s',datestr=date_format_str)
however the documentation doesn't specify how to format milliseconds. I've found this SO question which talks about microseconds, but a) I would prefer milliseconds and b) the following doesn't work on Python 2.6 (which I'm working on) due to the %f
:
logging.Formatter(fmt='%(asctime)s',datefmt='%Y-%m-%d,%H:%M:%S.%f')
A simple expansion that doesn't require the
datetime
module and isn't handicapped like some other solutions is to use simple string replacement like so:This way a date format can be written however you want, even allowing for region differences, by using
%F
for milliseconds. For example:This should work too:
The simplest way I found was to override default_msec_format:
After instantiating a
Formatter
I usually setformatter.converter = gmtime
. So in order for @unutbu's answer to work in this case you'll need:If you are using arrow or if you don't mind using arrow. You can substitute python's time formatting for arrow's one.
Now you can use all of arrow's time formatting in
datefmt
attribute.Adding msecs was the better option, Thanks. Here is my amendment using this with Python 3.5.3 in Blender