1、配置文件 log_conf.conf
################################################
###########propagate 是否继承父类的log信息,0:否 [loggers]
keys=root,example01,example02
[logger_root]
level=DEBUG
handlers=hand01,hand02
[logger_example01]
handlers=hand01,hand02
qualname=example01
propagate=0
[logger_example02]
handlers=hand01,hand03
qualname=example02
propagate=0
############################################### 你好哈哈哈哈你是谁
[handlers]
keys=hand01,hand02,hand03
[handler_hand01]
class=StreamHandler
level=DEBUG
formatter=form01
args=(sys.stderr,)
[handler_hand02]
class=FileHandler
level=DEBUG
formatter=form01
args=('..\\log_files\\AutoTestLog.log', 'a','utf-8')
[handler_hand03]
class=handlers.RotatingFileHandler
level=INFO
formatter=form01
args=('..\\log_files\\AutoTestLog.log', 'a', 10*1024*1024, 5,'utf-8') ## 应该是5M大小之后会滚动生成新文件
###############################################
[formatters]
keys=form01,form02
[formatter_form01]
format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s
datefmt=%Y-%m-%d %H:%M:%S
[formatter_form02]
format=%(name)-12s: %(levelname)-8s %(message)s
datefmt=%Y-%m-%d %H:%M:%S
2、log.py程序文件
from basic_config_vars.config_vars import logConfigPath import logging
import logging.config
print('********',logConfigPath) #上述配置文件的路径
logging.config.fileConfig(logConfigPath)
logger=logging.getLogger('example01') def debug(message):
print('debug')
logger.debug(message) def warning(message):
logger.warning(message) def info(message):
logger.info(message) def error(message):
logger.error(message) if __name__=='__main__':
debug('debug 你好吗')
info('大家好吗')
warning('waring 日志输出')