A log file configuration
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename=None, # './log/{}.log'.format(datetime.now().day), #不指定文件,会在窗口显示
filemode='w',
force=True)
-
level=logging.INFO
: This sets the minimum logging level to INFO , which means only INFO level and above logs will be logged.
-
format='%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s'
: This is the format string for the log. It contains the following information:
%(asctime)s
: A string representation of the recording time.
%(filename)s
: The source filename from which the logging call was made.
[line:%(lineno)d]
: Record the source file line number where the logging call was made.
%(levelname)s
: Log level (eg, INFO, WARNING, ERROR, etc.).
%(message)s
: The actual log message.
-
datefmt='%a, %d %b %Y %H:%M:%S'
: This is the format string of the recorded time, which is used to specify the display format of the time.
-
filename=None
: This specifies the filename for logging. If yes None
, the log will be output to the console.
-
filemode='w'
: This specifies the file mode, 'w'
which means write mode, and each log output will overwrite the previous content.
-
force=True
: This forces a log configuration change . If there are other log configurations before, this setting will override the previous configuration.