This article describes the python based on file size log logging method, share for everyone to reference. The specific methods are as follows:
Import glob
Import logging
import logging.handlers
log_filename= ' logging_rotatingfile_example.out '
# Set up a specific logger the desired output level
My_logger = Logging.getlogger (' MyLogger ')
My_logger. Setlevel (logging. DEBUG)
# ADD The log message handler to the logger
handler = Logging.handlers.RotatingFileHandler (log_filename,< C9/>maxbytes=20,
backupcount=5,
)
My_logger.addhandler (handler)
# Log Some messages for
I In range:
my_logger.debug (' i =%d '% i)
# What files are created
logfiles = Glob.glob ('%s* '% log_f ilename) for
filename in logfiles:
print filename
This instance can be used to loop log, the first file reached the MaxBytes size, the second file is written.
I hope this article will help you with your Python programming.