简体   繁体   English

使用 ruby 日志记录 gem 关闭日志轮换

[英]Turning off log rotation with ruby logging gem

I have some code I am maintaining that is using the logging ruby gem.我有一些我正在维护的代码正在使用日志记录 ruby gem。 I would like to use the linux logrotate tool instead of the gem to rotate the logs.我想使用 linux logrotate 工具而不是 gem 来旋转日志。 I'm using it inside some custom code to create separate log streams.我在一些自定义代码中使用它来创建单独的日志流。

require 'logging'
[...]
def create_logger(name)
   logger = Logging.logger[name]

Is there a way I can turn off log rotation after the logger object is created?创建记录器 object 后,有没有办法可以关闭日志轮换?

logger.age = 0 is not working. logger.age = 0不起作用。

The source code has good documentation , which only mentions setting rotation strategy on initialization, I don't think changing an existing instance's rotation strategy is a good idea as it could have unintended consequences.源代码有 很好的文档,它只提到在初始化时设置轮换策略,我不认为更改现有实例的轮换策略是一个好主意,因为它可能会产生意想不到的后果。

But, you could close the existing logger with logger.close and reopen it later with logger.reopen .但是,您可以使用logger.reopen logger.close打开它。

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

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