logger
logger copied to clipboard
Log rotation doesn't preserve file permissions
If you create a file with user permissions but then run logger under root the file rotate will not preserve these permissions causing access issues.
% ls -al log.log
-rw-r--r-- 1 reginaldsmith staff 0 23 Sep 11:17 log.log
% rvmsudo irb
2.7.2 :001 > require "logger"
=> true
2.7.2 :004 > puts File.stat("log.log").uid
502
=> nil
2.7.2 :005 > log = File.open("log.log", "a")
=> #<File:log.log>
2.7.2 :006 > logger = Logger.new(log, "everytime")
=> #<Logger:0x00007fd7cfbc5ee0 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007fd7cfbc5eb8 @datetime_format=nil>, @formatte...
2.7.2 :007 > logger.info "hello"
=> true
2.7.2 :008 > puts File.stat("log.log").uid
0
2.7.2 :010 > exit
% ls -al log.log
-rw-r--r-- 1 root staff 123 23 Sep 11:20 log.log
% irb
2.7.2 :001 > require "logger"
=> true
2.7.2 :002 > log = File.open("log.log", "a")
Errno::EACCES (Permission denied @ rb_sysopen - log.log)
>
Peeking at the code, perhaps this is where we have the information about the old file and are creating a new one: https://github.com/ruby/logger/blob/c601ed0370da6e509726cbabb22aaeaffeb3f477/lib/logger/log_device.rb#L201
(Perhaps there are more places, but this is a start, at least.)