This article mainly introduces python's log generation method based on the file size, which enables loop logging. that is, when the first file reaches the maxBytes size, it is written to the second file, and so on, it is a very practical technique. if you need it, you can refer to the example in this article to describe 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.