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

有什么比较好的真正的按照时间分割的日志文件么

  •  1
     
  •   18870715400 · Aug 26, 2020 · 2814 views
    This topic created in 2261 days ago, the information mentioned may be changed or developed.
    # 在用 logging 的时候发现
    file_handler = TimedRotatingFileHandler(filename=file_name, when='D', interval=1, backupCount=365)
    # 并不是准确的按照每天零点分割日志, 那么有什么比较好的按照时间分割日志文件的库呢
    
    8 replies  •  2020-08-28 00:10:45 +08:00
    j0hnj
    j0hnj
    Aug 26, 2020
    1
    我简单写了一个: https://gist.github.com/j178/7d5b6a7bf77233caf6c3ef530f00709f
    主要思路就是自定义 `shouldRollover` 的逻辑,你可以根据自己的需求修改
    Cooky
    Cooky
    Aug 26, 2020 via Android
    2
    logrotate ?
    xiaolinjia
    xiaolinjia
    Aug 26, 2020❤️1
    3
    TimedRotatingFileHandler(filename=file_name, when="midnight", interval=1)
    我寻思,官方文档里,0 点,不是 midnight ?
    j0hnj
    j0hnj
    Aug 26, 2020
    4
    @xiaolinjia #3 对哦,我都忘了还有这个参数了…感谢
    18870715400
    18870715400
    OP
    Aug 26, 2020
    5
    @xiaolinjia 午夜不就是零点么
    qile1
    qile1
    Aug 26, 2020 via Android
    6
    好像是不好分割,我在多进程里面,偶尔会出现切换日志文档时候,日志报错情况
    18870715400
    18870715400
    OP
    Aug 27, 2020
    7
    @qile1 多进程写入同一个日志文件可以将日志消息发给一个队列, 另起一个进程从队列中取消息再写入文件
    18870715400
    18870715400
    OP
    Aug 28, 2020
    8
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2938 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:21 · PVG 19:21 · LAX 03:21 · JFK 06:21
    ♥ Do have faith in what you're doing.