好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

0x02 Python logging模块利用配置加载logger

目录

logging模块利用配置加载logger 方式一模板:logging.config.dictConfig(config_dict)

logging模块利用配置加载logger

logging.config模块提供了从配置加载创建logger等相关对象,并放入manager对象中进行缓存待用。所以记录下一般几种方式配置的范本模式,方便项目中copy直接修改使用。

dict config references 官档关于logging配置字典说明

方式一模板:logging.config.dictConfig(config_dict)

config_dict 字典模板

cfg = {
        'version': 1,
        'formatters': {
            'detailed': {
                'class': 'logging.Formatter',
                'format': '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s'
            }
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'level': 'INFO',
            },
            'file': {
                'class': 'logging.FileHandler',
                'filename': 'mplog.log',
                'mode': 'w',
                'formatter': 'detailed',
            },
            'foofile': {
                'class': 'logging.FileHandler',
                'filename': 'mplog-foo.log',
                'mode': 'w',
                'formatter': 'detailed',
            },
            'errors': {
                'class': 'logging.FileHandler',
                'filename': 'mplog-errors.log',
                'mode': 'w',
                'level': 'ERROR',
                'formatter': 'detailed',
            },
        },
        'loggers': {
            'foo': {
                'handlers': ['foofile']
            }
        },
        'root': {
            'level': 'DEBUG',
            'handlers': ['console', 'file', 'errors']
        },
    }

查看更多关于0x02 Python logging模块利用配置加载logger的详细内容...

  阅读:23次