1:logger.conf
############################################### [loggers] keys=root,manylog,daylog [logger_root] level=DEBUG handlers=hand01,hand02 [logger_manylog] handlers=hand01,hand03 qualname=manylog propagate=0 [logger_daylog] handlers=hand01,hand04 qualname=daylog propagate=0 ############################################### [handlers] keys=hand01,hand02,hand03,hand04 [handler_hand01] class=StreamHandler level=DEBUG formatter=test args=(sys.stderr,) [handler_hand02] class=FileHandler level=DEBUG formatter=test args=('logs/log.log', 'a') [handler_hand03] class=handlers.RotatingFileHandler level=DEBUG formatter=online args=('logs/log.log', 'a', 50*1024*1024, 20) [handler_hand04] class=handlers.TimedRotatingFileHandler level=INFO formatter=online args=('logs/log_', 'D', 1, 0) ############################################### [formatters] keys=test,online [formatter_test] format=[%(asctime)s] [%(levelname)s] [%(filename)s:%(lineno)d] Msg:%(message)s datefmt=%Y-%m-%d %H:%M:%S [formatter_online] format=[%(asctime)s] [%(thread)d] [%(levelname)s] [%(filename)s:%(lineno)d] Msg:%(message)s datefmt=%Y-%m-%d %H:%M:%S
2:logger_factory.py
import logging import logging.config from app.common.file import app_path def log_factory(name='root'): log_conf = os.getcwd()+ '/logging.conf' logging.config.fileConfig(log_conf) logger = logging.getLogger(name) return logger