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

【Python】公共类-logger

时间:2020-01-26 18:58:01      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:import   asc   test   debug   deb   ror   roo   ESS   ctime   

# -*- 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

标签:import   asc   test   debug   deb   ror   roo   ESS   ctime   

原文地址:https://www.cnblogs.com/haohaozhang/p/11363363.html

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