ssp4599815
2/7/2018 - 3:41 AM

python_rotate_logging

python logging 版本的简单应用

import logging
from logging.handlers import RotatingFileHandler
# logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler(
    '/tmp/log/process_time.log',
    maxBytes=1024*1024*10,
    backupCount=10,
    encoding='utf-8'
)
handler.setFormatter(
    logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
)
logger.addHandler(handler)

###
logger.info(gears)