首页 > 其他 > 详细

IO多路复用概念性

时间:2017-04-25 23:00:35      阅读:195      评论:0      收藏:0      [点我收藏+]

Logiging模块日志级别

CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0

只能写入到一个文件,多次声明无效
import logging

logging.basicConfig(
#     filename=‘l1.log‘,
#     format=‘%(asctime)s - %(name)s - %(levelname)s -%(module)s:  %(message)s‘,
#     datefmt=‘%Y-%m-%d %H:%M:%S %p‘,
#     level=logging.INFO      #这里定义这个值是阀值,如果超过这个数了才会写入文件中
# )
# logging.log(logging.ERROR,‘123123‘)

所以我们只能自定义

def error_log(message):
    #创建文件对象
    file_1_1 = logging.FileHandler(error.log, a+, encoding=utf-8)
    fmt = logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s -%(module)s:  %(message)s")
    file_1_1.setFormatter(fmt)
    # 创建日志对象
    logger1 = logging.Logger(error, level=logging.ERROR)
    
    # 日志对象和文件对象创建关系
    logger1.addHandler(file_1_1)

    logger1.log(logging.FATAL,message)

def run_log(message):
    file_1_1 = logging.FileHandler(run.log, a+, encoding=utf-8)
    fmt = logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s -%(module)s:  %(message)s")
    file_1_1.setFormatter(fmt)
    # 创建日志对象
    logger1 = logging.Logger(run, level=logging.ERROR)
    # 日志对象和文件对象创建关系
    logger1.addHandler(file_1_1)

    logger1.log(logging.FATAL,message)

traceback模块

详细错误信息打印

class NicPlugin(BasePlugin):
    def linux(self):
        """
        执行命令,获取资产信息
        :return:
        """
        ret = BaseResponse()
        try:
            result = self.cmd(nic)
            ret.data = result
        except Exception as e:
            v = traceback.format_exc() 
            ret.status = False
            ret.error = v
            # 写入本地日志
            obj = LoggerHelper.instance()
            obj.error_logger.log(50,v)
        return ret

 

IO多路复用概念性

原文:http://www.cnblogs.com/zcqdream/p/6764852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!