logger icon indicating copy to clipboard operation
logger copied to clipboard

Default shift values not available to logfiles set from #reopen

Open titusfortner opened this issue 4 years ago • 0 comments

This code correctly sets @shift_age to 7 and @shift_size to 1048576

Logger::LogDevice.new(@filename)

This code will end up with those instance variables set to nil

logger = Logger::LogDevice.new(STDERR)
logger.reopen(@filename)

This could be fixed in LogDevice#initialize by setting the defaults outside of the if @filename condition, or repeating the logic in the LogDevice#reopen.

It would also make sense, though, if you can update the output to be able to also change those values if desired. This could be done by adding an attr_writer for them.

The best course of action would be to support adding/changing the values when a new output is specified. I'm adding a PR with my recommendation.

My specific use case involves a library I'm using instantiating a logger instance for me with STDOUT, and I want to change the output to a file with useful shift values.

titusfortner avatar Mar 26 '21 03:03 titusfortner