diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-21 07:11:03 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-21 07:11:03 +0000 |
commit | 82d495134c4961d3d6099d1186da978f03bac988 (patch) | |
tree | bd5afaa64ed39a0abec3dc9490d242d71dd68b23 /test | |
parent | e00bcd1df330bc70af8fa3259be074e861873476 (diff) | |
download | ruby-82d495134c4961d3d6099d1186da978f03bac988.tar.gz |
logger.rb: fix midnight log rotation miss
* lib/logger.rb (Logger::LogDevice#check_shift_log): compare the
current time with the time for the next rotation to fix rotation
miss when date changed between the comparison and log writing.
based on the patch by megayu <yuhg2310 AT gmail.com>.
[Fixes GH-539]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/logger/test_logdevice.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/logger/test_logdevice.rb b/test/logger/test_logdevice.rb index 7999135dd9..3db3a5da45 100644 --- a/test/logger/test_logdevice.rb +++ b/test/logger/test_logdevice.rb @@ -326,6 +326,42 @@ class TestLogDevice < Test::Unit::TestCase end end unless /mswin|mingw/ =~ RUBY_PLATFORM + def test_shifting_midnight + Dir.mktmpdir do |tmpdir| + assert_ruby_status([*%W"--disable=gems -rlogger -C#{tmpdir} -"], <<-'end;') + begin + module FakeTime + attr_accessor :now + end + + class << Time + prepend FakeTime + end + + log = "log" + File.open(log, "w") {} + File.utime(*[Time.mktime(2014, 1, 1, 23, 59, 59)]*2, log) + + Time.now = Time.mktime(2014, 1, 2, 23, 59, 59, 999000) + dev = Logger::LogDevice.new(log, shift_age: 'daily') + dev.write("#{Time.now} hello-1\n") + + File.utime(*[Time.mktime(2014, 1, 3, 0, 0, 0, 121000)]*2, log) + Time.now = Time.mktime(2014, 1, 3, 1, 1, 1) + dev.write("#{Time.now} hello-2\n") + ensure + dev.close + end + end; + + bug = '[GH-539]' + log = File.join(tmpdir, "log") + assert_match(/hello-2/, File.read(log)) + assert_file.for(bug).exist?(log+".20140102") + assert_match(/hello-1/, File.read(log+".20140102"), bug) + end + end + private def run_children(n, args, src) |