logging is very important, use a simple note-taking.

Reference links:

https://www.cnblogs.com/CJOKER/p/8295272.html

https://www.cnblogs.com/deeper/p/7404190.html

https://www.jianshu.com/p/feb86c06c4f4

https://zhuanlan.zhihu.com/p/42638567 (recommended know almost see this in.)

Reference books: Python3 standard library, Python programming and running quickly.

First of all tell us about, why use logging, quick start construed in accordance with the Python programming book. Although the need to set up each logging using logging.basicConfig,

But the benefits are obvious, when you do not want to output logging output time, just need logging, disable with the highest level adjustment to it.

 

I first prime minister on a format common format specification
% (levelno) s: print the log level value
% (levelname) s: Print log level names
% (pathname) s: print path of the currently executing program, in fact, sys.argv [0 ]
% (filename) S: Print executing program name
% (funcName) s: current function of the printing log
% (lineno) d: printing log of the current line number
% (asctime) s: time printing log
% (thread) d : print thread ID
% (threadName) S: print thread name
% (process) d: Print process ID
% (the message) S: print log information

 

English version:

 

The format of the optional parameters are as follows (Python 3.5):

 

%(asctime)s: Human-readable time when theLogRecordwas created. By default this is of the form ‘2003-07-08 16:49:45,896’ (the numbers after the comma are millisecond portion of the time).

 

%(created)f: Time when theLogRecordwas created (as returned bytime.time()).

 

%(filename)s: Filename portion ofpathname.

 

%(funcName)s: Name of function containing the logging call.

 

%(levelname)s: Text logging level for the message ('DEBUG','INFO','WARNING','ERROR','CRITICAL').

 

%(levelno)s: Numeric logging level for the message (DEBUG,INFO,WARNING,ERROR,CRITICAL).

 

%(lineno)d: Source line number where the logging call was issued (if available).

 

%(module)s: Module (name portion offilename).

 

%(msecs)d: Millisecond portion of the time when theLogRecordwas created.

 

%(message)s: The logged message, computed asmsg%args. This is set whenFormatter.format()is invoked.

 

%(name)s: Name of the logger used to log the call.

 

%(pathname)s: Full pathname of the source file where the logging call was issued (if available).

 

%(process)d: Process ID (if available).

 

%(processName)s: Process name (if available).

 

%(relativeCreated)d: Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded.

 

%(thread)d: Thread ID (if available).

 

%(threadName)s: Thread name (if available).

 

 

 

After writing this basicConfig inside to use, easy to remember to write in the beginning.

 

First the simple code:

the logging Import 
logging.basicConfig (Level = logging.DEBUG) 
# logging.disable (logging.CRITICAL) # This level may be provided, provided that level, the level of the content to the level of the following will not be executed. 
logging.debug ( 'Hello') 
logging.info ( 'Hello') 
logging.warning ( 'Hello') 
logging.error ( 'Hello') 
logging.critical ( 'Hello')

 

 

/usr/local/bin/python3.7 /Users/shijianzhong/study/t_logging/t1.py
DEBUG:root:hello
INFO:root:hello
WARNING:root:hello
ERROR:root:hello
CRITICAL:root:hello

 As can be seen from the output, the default output level information, the second% (name) s ,, third message.

Briefly record it, logging but it is still very complex, such as when used in the follow-up, again to add relevant content.

 

 

Guess you like

Origin www.cnblogs.com/sidianok/p/12020130.html