python study notes two: (function format description python3 logging)

  • Background, learning always have problems logging can not understand, summarize, try to provide clarity, let's get started!

                                                        

  • Common logging module format Format Description

  • % (Levelno) s: printing log level values
  • % (Levelname) s: Print the name of the log level
  • % (Pathname) s: print path currently executing program, in fact, sys.argv [0]
  • % (Filename) s: Print the name of the currently executing program, python such as: login.py
  • % (FuncName) s: printing log current function
  • % (Lineno) d: the current line number of the printing log, the log in the first few lines of printing
  • % (Asctime) s: time printing log
  • % (Thread) d: Print thread ID
  • % (ThreadName) s: print thread name
  • % (Process) d: Print Process ID
  • % (Message) s: print log information
  • Use pre-understanding:

    1. logging.basicConfig function of the parameters:
    2.  filename: Specify the log file name, such as my.log or my.txt
    3.  the same meaning and function file, the log file open mode specified,: the fileMode 'W' or 'a'
    4. format: designated output format and content, format may output a lot of useful information in the following example:
    5. datefmt: Specifies the time format, with time.strftime ()
    6. level: set the log level, the default is logging.WARNING
    7. stream: Specifies the output stream of the log, can specify the output to sys.stderr, sys.stdout or file, the default output to sys.stderr, and the filename specified when the stream at the same time, are ignored stream

logging in using the format:

Example 1: Test specified file 
logging.basicConfig (Level = logging.DEBUG,
the format = '% (the asctime) S% (filename) S [Line:% (lineno) D]% (levelname) S% (Message) S',
= datefmt '% a,% B% D% the Y% H:% M:% S',
filename = 'myapp.txt',
the fileMode = 'W')
logging.debug ( "this is a debug")

The results:

 

Example 2: no file, the print log window

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filemode='w')

Results of the:

 

                                                                                                       更多快乐分享进群 :

 

Guess you like

Origin www.cnblogs.com/yoyoblogs/p/10948052.html