aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/logger.rb17
-rw-r--r--test/logger/test_logdevice.rb38
3 files changed, 49 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 9af231e766..9dd67f27e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Fri Feb 21 16:11:02 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Feb 21 16:45:54 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/logger.rb (next_rotate_time, previous_period_end): consider
+ DST change.
* lib/logger.rb (Logger::LogDevice#check_shift_log): compare the
current time with the time for the next rotation to fix rotation
diff --git a/lib/logger.rb b/lib/logger.rb
index ef9c75d068..ca667f48b4 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -714,29 +714,26 @@ private
when /^monthly$/
t = Time.mktime(now.year, now.month, 1) + SiD * 31
mday = (1 if t.mday > 1)
- if mday
- t = Time.mktime(t.year, t.month, mday)
- end
else
return now
end
+ if mday or t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
+ t = Time.mktime(t.year, t.month, mday || (t.mday + (t.hour > 12 ? 1 : 0)))
+ end
t
end
def previous_period_end(now, shift_age)
case shift_age
when /^daily$/
- eod(now - 1 * SiD)
+ t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
when /^weekly$/
- eod(now - ((now.wday + 1) * SiD))
+ t = Time.mktime(now.year, now.month, now.mday) - (SiD * (now.wday + 1) + SiD / 2)
when /^monthly$/
- eod(now - now.mday * SiD)
+ t = Time.mktime(now.year, now.month, 1) - SiD / 2
else
- now
+ return now
end
- end
-
- def eod(t)
Time.mktime(t.year, t.month, t.mday, 23, 59, 59)
end
end
diff --git a/test/logger/test_logdevice.rb b/test/logger/test_logdevice.rb
index 3db3a5da45..0245d03eba 100644
--- a/test/logger/test_logdevice.rb
+++ b/test/logger/test_logdevice.rb
@@ -362,6 +362,44 @@ class TestLogDevice < Test::Unit::TestCase
end
end
+ def test_shifting_dst_change
+ Dir.mktmpdir do |tmpdir|
+ system({"TZ"=>"Europe/London"}, EnvUtil.rubybin, *%W"--disable=gems -rlogger -C#{tmpdir} -e", <<-'end;')
+ begin
+ module FakeTime
+ attr_accessor :now
+ end
+
+ class << Time
+ prepend FakeTime
+ end
+
+ log = "log"
+ File.open(log, "w") {}
+
+ Time.now = Time.mktime(2014, 3, 30, 0, 1, 1)
+ File.utime(Time.now, Time.now, log)
+
+ dev = Logger::LogDevice.new(log, shift_age: 'daily')
+ dev.write("#{Time.now} hello-1\n")
+ File.utime(*[Time.mktime(2014, 3, 30, 0, 2, 3)]*2, log)
+
+ Time.now = Time.mktime(2014, 3, 31, 0, 1, 1)
+ File.utime(Time.now, Time.now, log)
+ dev.write("#{Time.now} hello-2\n")
+ ensure
+ dev.close
+ end
+ end;
+
+ log = File.join(tmpdir, "log")
+ cont = File.read(log)
+ assert_match(/hello-2/, cont)
+ assert_not_match(/hello-1/, cont)
+ assert_file.exist?(log+".20140330")
+ end
+ end
+
private
def run_children(n, args, src)