加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 10:38:55 所属栏目:Python 来源:网络整理
导读:目录 logging模块利用配置加载logger 方式一模板:logging.config.dictConfig(config_dict) logging模块利用配置加载logger logging.config模块提供了从配置加载创建logger等相关对象,并放入manager对象中进行缓存待用。所以记录下一般几种方式配置的范本模

目录

  • 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','errors': {
                'class': 'logging.FileHandler','filename': 'mplog-errors.log','level': 'ERROR','loggers': {
            'foo': {
                'handlers': ['foofile']
            }
        },'root': {
            'level': 'DEBUG','handlers': ['console','file','errors']
        },}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读