python module -logging

python module logging

import logging

### Simple usage format Log level CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET

logging.debug('debug message') # logging.log level('user output information')
logging.info('info message')  
logging.warning('warning message')  
logging.error('error message')  
logging.critical('critical message')

### Configure log output

logging.basicConfig(level=logging.DEBUG,  
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',  
                    datefmt='%a, %d %b %Y %H:%M:%S', #output time format
                    filename='/tmp/test.log',          
                    filemode = 'w')  
  
Format strings that may be used in the format parameter:
%(name)s Logger's name
%(levelno)s Digital log level
%(levelname)s Text log level
%(pathname)s The module that calls the log output function The full path name of the log output function, may not be
%(filename)s The file name of the module calling the log output function
%(module)s The module name of the log output function
call%(funcName)s The function name of the log output function call
%(lineno)d The line of code where the statement that calls the log output function is located
%(created)f The current time, expressed as a floating point number representing time in UNIX standard
%(relativeCreated)d When outputting log information, the number of milliseconds since the Logger was created
%(asctime) s The current time as a string. The default format is "2003-07-08 16:49:45,896". After the comma is the millisecond
%(thread)d thread ID. There may be no
%(threadName)s thread names. There may be no
%(process)d process ID. There may be no
%(message)s user output messages




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325037233&siteId=291194637