Bug #9133
closedlogger rotates log files more than expected
Description
=begin
(This may be a same problem as #9130, but this also happens with 2.0.0 and 1.9.3.)
Logger rotates log files more than expected as follow:
SH> rm -f log*
A>> logger = Logger.new("log", 1, 200)
B>> logger = Logger.new("log", 1, 200)
SH> ls -r | xargs head -v
==> log <==
Logfile created on 2013-11-21 11:02:25 +0900 by logger.rb/31641¶
A>> 3.times{logger.fatal("FATAL")}
SH> ls -r | xargs head -v
==> log <==
Logfile created on 2013-11-21 11:02:25 +0900 by logger.rb/31641¶
F, [2013-11-21T11:02:46.935514 #3164] FATAL -- : FATAL
F, [2013-11-21T11:02:46.935700 #3164] FATAL -- : FATAL
F, [2013-11-21T11:02:46.935767 #3164] FATAL -- : FATAL
A>> logger.debug("DEBUG") # <- trigger for rotation
SH> ls -r | xargs head -v
==> log.0 <==
Logfile created on 2013-11-21 11:02:25 +0900 by logger.rb/31641¶
F, [2013-11-21T11:02:46.935514 #3164] FATAL -- : FATAL
F, [2013-11-21T11:02:46.935700 #3164] FATAL -- : FATAL
F, [2013-11-21T11:02:46.935767 #3164] FATAL -- : FATAL
==> log <==
Logfile created on 2013-11-21 11:03:00 +0900 by logger.rb/31641¶
D, [2013-11-21T11:03:00.301294 #3164] DEBUG -- : DEBUG
B>> logger.debug("DEBUG") # <- also trigger for rotation (unintended)
SH> ls -r | xargs head -v
==> log.0 <==
Logfile created on 2013-11-21 11:03:00 +0900 by logger.rb/31641¶
D, [2013-11-21T11:03:00.301294 #3164] DEBUG -- : DEBUG
==> log <==
Logfile created on 2013-11-21 11:03:11 +0900 by logger.rb/31641¶
D, [2013-11-21T11:03:11.315164 #3169] DEBUG -- : DEBUG
In this case, two DEBUG lines displace the three FATAL lines even
though enough space is still left on "log" at that time.
Logger decides to rotate log files by checking @logdev.dev.stat.size.
In case of @logdev.dev already rotated by another process, so logger
actually checks the size of "log.0".