Python公共类-logger
Posted 巧克力脆片
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python公共类-logger相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*- __author__ = ‘zhangh‘ import logging class Logging(object): def __init__(self, path): self.path = path def log(self): log_format = logging.Formatter("%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s") logger = logging.getLogger() logging_file = logging.FileHandler(self.path) logging_file.setFormatter(log_format) logging_stream = logging.StreamHandler() logging_stream.setFormatter(log_format) logger.addHandler(logging_file) logger.addHandler(logging_stream) logger.setLevel("DEBUG") return logger # logger = Logging(‘/root/Desktop/test.log‘).log() # logger.info(‘info message‘) # logger.warning(‘warning message‘) # logger.error(‘warning message‘) # logger.debug(‘debug message‘) # logger.critical(‘critical message‘)
以上是关于Python公共类-logger的主要内容,如果未能解决你的问题,请参考以下文章