Python:将单独的进程记录到同一文件吗? [英] Python: separate processes logging to same file?

查看:108
本文介绍了Python:将单独的进程记录到同一文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python的logging库是否为两个(或更多)单独的python进程提供序列化日志记录?从文档(我已经阅读过)看来还不清楚.

Does Python's logging library provide serialised logging for two (or more) separate python processes logging to the same file? It doesn't seem clear from the docs (which I have read).

如果是这样,那么在完全不同的机器上(共享日志文件将存在于两个人均可访问的NFS导出上)怎么办?

If so, what about on completely different machines (where the shared log file would exist on an NFS export accessible by both).

推荐答案

否,不支持.来自python 记录食谱:

No it is not supported. From python logging cookbook:

尽管日志记录是线程安全的,并且可以从日志记录到单个文件 支持单个进程中的多个线程,登录到单个线程 不支持来自多个进程的文件,因为没有 跨多个序列化对单个文件的访问的标准方法 Python中的进程.

Although logging is thread-safe, and logging to a single file from multiple threads in a single process is supported, logging to a single file from multiple processes is not supported, because there is no standard way to serialize access to a single file across multiple processes in Python.

此后,菜谱建议使用一个套接字服务器进程来处理日志,而其他进程则向日志服务器发送日志消息. 通过网络发送和接收日志记录事件.

Afterwards the cookbook suggests to use a single socket-server process that handles the logs and the other processes sending log messages to it. There is a working example of this apporach in the section Sending and Receiving logging events across a network.

这篇关于Python:将单独的进程记录到同一文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆