推荐学习书目
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
meishild
V2EX  ›  Python

Python 日志 TimedRotatingFileHandler 和 django 的 USE_L10N 冲突

  •  
  •   meishild · Mar 1, 2016 · 4355 views
    This topic created in 3729 days ago, the information mentioned may be changed or developed.
    如果设置 USE_L10N=True 则日志打印和分割都是没有问题的,但是我在 admin 无法自定义时间的显示格式。
    如果设置 USE_L10N=False 日志内容没问题但是日志的分割是错误的时间不是每日间隔的时间是中午 11 点左右,我怀疑是 USE_L10N=False 的时候导致 logger 在获取时间的时候异常但是一直查不出来需要如果修改
    2 replies    2018-09-15 12:05:32 +08:00
    meishild
        1
    meishild  
    OP
       Mar 1, 2016
    不只是按日分割有问题。。
    import logging, logging.handlers

    log = logging.getLogger('')
    log.setLevel(logging.DEBUG)
    format = "%(asctime)s %(message)s"
    formater = logging.Formatter(format)
    handler = logging.handlers.TimedRotatingFileHandler("test.log", "M", 1, 0)
    handler.suffix = "%Y%m%d.%H%M"
    handler.setFormatter(formater)
    log.addHandler(handler)
    log.debug("test log")

    不停打印日志 就发现分割错误
    lufangfan
        2
    lufangfan  
       Sep 15, 2018
    老哥,我遇到了跟你一样的问题,就是 admin 的时候想显示格式化时间,必须把 USE_L10N 设置成 False,有没有不改这个设置也能在 admin 显示到秒的方法啊?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3071 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:41 · PVG 20:41 · LAX 05:41 · JFK 08:41
    ♥ Do have faith in what you're doing.