Python logs log _python based on file size

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.