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

解决一个问题,分享一个库 LoggerServer。

  •  1
     
  •   kehr ·
    kehr · Nov 16, 2017 · 1544 views
    This topic created in 3099 days ago, the information mentioned may be changed or developed.

    实现 Python 多进程日志采用 logging 模块打印到同一个文件的需求。

    logging 模块是线程安全的,支持多线程打印,所以多个线程向同一个日志文件打日志完全没问题。最近开发的项目为了利用多核(用的 CPython ),起了多个实例并向同一个文件打日志,后续发现有日志丢失的情况。

    查文档,找到了官方说明:logging cookbook

    虽然官方给了示例,但考虑到客户端日志量大,过高的 QPS 可能会导致日志服务处理不过来。正好对 Tornado 比较熟悉,就用 Tornado 的 TCPServerioloop 写了一个日志服务器,文档和说明都整理好了,公司的项目也在用,拿出来大家看看还有什么问题和优化的地方。

    文档参见:LoggerServer Documentaion

    觉得还不错的同学,点个 star 吧: https://github.com/kehr/LoggerServer

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4233 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 00:56 · PVG 08:56 · LAX 17:56 · JFK 20:56
    ♥ Do have faith in what you're doing.