Python logs based on the file size,
The example in this article describes how to log by file size in python and share it with you for your reference. The specific method is as follows:
Import glob import logging. handlers LOG_FILENAME = 'logging _ rotatingfile_example.out '# Set up a specific logger with our 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, maxBytes = 20, backupCount = 5,) my_logger.addHandler (handler) # Log some messages for I in range (20): my_logger.debug ('I = % d' % I) # See what files are created logfiles = glob. glob ('% s *' % LOG_FILENAME) for filename in logfiles: print filename
This instance can implement cyclic logging. When the first file reaches the maxBytes size, it is written to the second file.
I hope this article will help you with Python programming.