推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
whathefoxsay
V2EX  ›  Python

如何优雅的使用 python logging 模块。。。。

  •  
  •   whathefoxsay · May 4, 2015 · 5279 views
    This topic created in 4217 days ago, the information mentioned may be changed or developed.
    我的方式:
    handler = handlers.RotatingFileHandler(LOG,'a',MAX_SIZE)
    level = logger.INFO
    logger = logging.getLogger(__name__)
    logger.setLevel(level)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setLevel(level)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    现在想将日志的配置和初始化分开,在之前django的配置中见过以比较优雅的使用dict来配置log, 请教是否有模板可以使用?
    7 replies  •  2015-05-04 18:24:50 +08:00
    hhkbp2
    hhkbp2
    May 4, 2015
    1
    写个函数把要变化的参数抽取出来,是不是就可以了
    lyief
    lyief
    May 4, 2015
    2
    建议把logger的配置写成文件,“易变参数写成配置文件”是我觉得很优雅的工程实践。
    des
    des
    May 4, 2015 via Android
    3
    楼主混知乎的吧?
    liboyue
    liboyue
    May 4, 2015
    4
    优雅的 => 优雅地
    goodryb
    goodryb
    May 4, 2015
    5
    logging模块是可以通过配置文件来初始化,这样代码基本可以保持不动
    有需求改配置文件就可以了
    whathefoxsay
    whathefoxsay
    OP
    May 4, 2015
    7
    @staticor 看到了使用dict来组织日志的配置文件,但是是基于django的,我想在我的系统里也有使用结构的配置方式,要自己写一个加载程序吗。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4070 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 09:23 · PVG 17:23 · LAX 01:23 · JFK 04:23
    ♥ Do have faith in what you're doing.