简体   繁体   English

Twisted Python-扭曲-如何删除旧的日志文件

[英]Twisted Python - twistd - How to remove old log files

I am using twistd to run my application, and I read how to customize the logger . 我正在使用twistd运行我的应用程序,并且阅读了如何自定义记录器 However, I can't seem to figure out how to get the default logger ( -l option, uses sequential integers for extensions) or the DailyLogFile to limit the number of rotated logs. 但是,我似乎无法弄清楚如何获取默认记录器( -l选项,对扩展使用顺序整数)或DailyLogFile来限制旋转日志的数量。 I'd ideally like the rotated log files to have date extensions in "%Y-%m-%d" format and be limited to 7 at a time. 理想情况下,我希望旋转的日志文件具有“%Y-%m-%d”格式的日期扩展名,并且一次限制为7个。

I tried using logrotate on my system, but I found that it inexplicably puts binary data in the log file when it does a copytruncate . 我尝试在系统上使用logrotate ,但是发现它执行copytruncate时,莫名其妙地将二进制数据放入日志文件中。

EDIT: I believe the reason for the binary data may be similar to this answer . 编辑:我相信二进制数据的原因可能类似于此答案

For the default logger, you can specify maxRotatedFiles which will limit the number of files created. 对于默认记录器,您可以指定maxRotatedFiles ,它将限制创建的文件数。 See this answer for an example https://stackoverflow.com/a/32273153/66349 参见以下答案以获取示例https://stackoverflow.com/a/32273153/66349

The DailyLogFile class doesn't support this option. DailyLogFile类不支持此选项。 There is a patch to add the functionality but I believe (from memory) it hasn't been accepted yet as it's missing a few tests and/or doesn't meet some code style guidelines. 有一个补丁可以添加功能,但是我相信(从内存中)它尚未被接受,因为它缺少一些测试和/或不符合某些代码样式准则。

Also note that twisted changed their logging system recently so this is all considered legacy now. 另请注意,Twisted最近更改了其日志记录系统,因此现在都认为这是旧的。 It still works but that may change at some point. 它仍然有效,但是可能会在某些时候改变。 Here's a link to the new twisted.logger docs https://twisted.readthedocs.io/en/latest/core/howto/logger.html 这是新的twisted.logger文档的链接https://twisted.readthedocs.io/en/latest/core/howto/logger.html

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

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