logging icon indicating copy to clipboard operation
logging copied to clipboard

Turnning off log rotation

Open cyclingzealot opened this issue 3 years ago • 2 comments

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.

cyclingzealot avatar Aug 12 '22 18:08 cyclingzealot

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 avatar Sep 07 '22 18:09 TwP

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.

TwP avatar Sep 07 '22 18:09 TwP