简体   繁体   English

在python中跨不同模块登录到单个文件

[英]Logging to a single file across different modules in python

I have a python project where I want to log multiple events across different modules in a single rotating file. 我有一个python项目,我想在一个旋转文件中记录跨不同模块的多个事件。 I am using logzero for this. 我为此使用logzero

For example: If I need logging from init .py and main .py, how can I using only a single log file to log both the events? 例如:如果我需要从init .py和main .py中进行日志记录,如何仅使用单个日志文件记录两个事件?

You can specify the same log file from different python files: 您可以从不同的python文件中指定相同的日志文件:

logzero.logfile("logfile.log", maxBytes=1000000, backupCount=3)

It is mentioned in the documentation (Features section): 文档 (功能部分)中提到了它:

Multiple loggers can write to the same logfile (also across multiple Python files). 多个记录器可以写入同一个日志文件(也可以跨多个Python文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM