Logging.basicconfig (level=log_level, format='% (asctime) s% (filename) s[line:% (Lineno) d ]% (levelname) s% (message) s', datefmt='%a,%d%b%Y%h:%m:%s' , filename='parser_result.log', filemode= ' W ')
logging.basicconfig function Parameters: FileName: Specifies the log file name FileMode: The same as the file function, specify the open mode of the log files,'W'Or'a'Format : Specifies the formats and contents of the output, format can output a lot of useful information, as in the example above:%(Levelno) S: Print the value of the log level%(levelname) S: Print log level name% (pathname) s: Prints the path of the currently executing program, which is actually sys.argv[0] %(filename) S: Print the current name of the executing program%(funcName) s: Print the current function of the log%(Lineno) d: Print the current line number of the log%(asctime) s: Time to print the log%(thread) d: Print thread ID%(threadname) s: Print thread name%(process) d: Print process ID%(message) s: Print log information datefmt: Specifies the time format, same as Time.strftime () level: Sets the log levels by default to logging. Warningstream: Specifies the output stream that will log, can specify output to Sys.stderr, Sys.stdout or file, default output to Sys.stderr, when stream and filename are specified simultaneously, stream is ignored logging print information function: Logging.debug ('This is debug message') logging.Info('This is info message') logging.warning ('This is warning message')
Python logging module Basicconfig configuration file