Hướng dẫn format time logging python
I am new to Python's logging package and plan to use it for my project. I would like to customize the time format to my taste. Here is a short code I copied from a tutorial:
And here is the output:
I would like to shorten the time format to just: '
fedorqui 259k99 gold badges523 silver badges576 bronze badges asked Jul 10, 2010 at 17:56
From the official documentation regarding the Formatter class:
So change
to
answered Jul 10, 2010 at 18:05
MetalsharkMetalshark 7,8847 gold badges33 silver badges49 bronze badges 5 Using
This allows you to format & config all in one line. A resulting log record looks as follows:
Eb946207 7188 silver badges26 bronze badges answered May 26, 2014 at 16:26
BenBen 4,2083 gold badges20 silver badges31 bronze badges 4 To add to the other answers, here are the variable list from Python Documentation.
answered May 30, 2017 at 1:40
IacchusIacchus 2,4342 gold badges27 silver badges23 bronze badges 2 if using logging.config.fileConfig with a configuration file use something like:
answered May 25, 2011 at 15:34
criptoncripton 4855 silver badges9 bronze badges Try These Formats:Format 1:
Output of Format 1: Format 2:
Output of Format 2: answered Mar 31, 2021 at 12:31
Amar KumarAmar Kumar 2,0532 gold badges19 silver badges32 bronze badges 0 In order to customize time format while logging we can create a logger object and and a fileHandler to it.
answered Feb 11 at 11:06
devpdevp 1,9712 gold badges12 silver badges23 bronze badges |