TwP / logging

A flexible logging library for use in Ruby programs based on the design of Java's log4j library.
https://rubygems.org/gems/logging
MIT License
530 stars 101 forks source link

Turnning off log rotation #241

Closed cyclingzealot closed 3 weeks ago

cyclingzealot commented 1 year ago

I have some code I am maintaining that is using the logging ruby gem. I would like to use the linux logrotate tool instead of the gem to rotate the logs. 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?

logger.age = 0 is not working.

TwP commented 1 year ago

The logging gem does not enable any log rotation by default. It must be configured manually via the RollingFile appender.

I'd suggest searching through your code for references to RollingFile or rolling_file.

TwP commented 1 year ago

But to answer your original question, you would need to use the logger.remove_appenders method to remove the rolling file appender. Then you would have to add a regular file appender to replace the one you just removed.

The RollingFile appender does not provide hooks for dynamically changing the interval when log files are rotated.