Python loop log

Source: Internet
Author: User
Python loop log

Refer:

Http://docs.python.org/2/library/logging.html

Rotatingfilehandler is used to process cyclic logs. You can specify the log file level, maximum log file capacity (in bytes), and log files.

#!/usr/bin/python# filename: printlog.py# author: # date: 2012-12-19# version: 0.1import loggingfrom logging.handlers import RotatingFileHandler## log settingsLOG_PATH_FILE = "./print.log"LOG_MODE = 'a'LOG_MAX_SIZE = 2*1024*1024 # 2MLOG_MAX_FILES = 4 # 4 Files: print.log.1, print.log.2, print.log.3, print.log.4LOG_LEVEL = logging.DEBUGLOG_FORMAT = "%(asctime)s %(levelname)-10s[%(filename)s:%(lineno)d(%(funcName)s)] %(message)s"handler = RotatingFileHandler(LOG_PATH_FILE, LOG_MODE, LOG_MAX_SIZE, LOG_MAX_FILES)formatter = logging.Formatter(LOG_FORMAT)handler.setFormatter(formatter)Logger = logging.getLogger()Logger.setLevel(LOG_LEVEL)Logger.addHandler(handler)i=0while i < 10000:  i = i+1  Logger.log(logging.DEBUG, "Logs a message with integer level lvl on this logger.")  Logger.info("Logs a message with level INFO on this logger.")  Logger.warning("Logs a message with level WARNING on this logger.")  Logger.error("Logs a message with level ERROR on this logger.")  Logger.critical("Logs a message with level CRITICAL on this logger.")# Logger.exception("This method should only be called from an exception handler.")

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.