码迷,mamicode.com
首页 > 编程语言 > 详细

Python的logger配制文件

时间:2018-01-12 18:11:42      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:mat   log   asc   style   logs   def   文件   formatter   .config   

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

 

Python的logger配制文件

标签:mat   log   asc   style   logs   def   文件   formatter   .config   

原文地址:https://www.cnblogs.com/feiyun126/p/8277076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!