aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-27 07:18:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-27 07:18:14 +0000
commit53cb3d741b2006c46c0a9b9df7f5b2d875d2e262 (patch)
tree245c06b486c7a86491c0d7e98f299354065a081f
parenta1aeefaf093cd6ec966881f062097c2671c5bf44 (diff)
downloadruby-53cb3d741b2006c46c0a9b9df7f5b2d875d2e262.tar.gz
logger.rb: end of week should be Saturday
* lib/logger.rb (Logger::Period#previous_period_end): as weekly rotation shifts the log file on Sundays, the end date of the previous period should be Saturdays. fix r45072. [ruby-dev:49314] [Bug #11622] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/logger.rb2
-rw-r--r--test/logger/test_logdevice.rb43
3 files changed, 51 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index bf3c23f58e..eb6dc638ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Oct 27 16:18:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/logger.rb (Logger::Period#previous_period_end): as weekly
+ rotation shifts the log file on Sundays, the end date of the
+ previous period should be Saturdays. fix r45072.
+ [ruby-dev:49314] [Bug #11622]
+
Tue Oct 27 16:12:37 2015 NARUSE, Yui <naruse@ruby-lang.org>
* vm_dump.c (rb_print_backtrace): our addr2line doesn't work on sparc.
diff --git a/lib/logger.rb b/lib/logger.rb
index 354d5aff71..f15a85077e 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -556,7 +556,7 @@ private
when 'daily'
t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
when 'weekly'
- t = Time.mktime(now.year, now.month, now.mday) - (SiD * (now.wday + 1) + SiD / 2)
+ t = Time.mktime(now.year, now.month, now.mday) - (SiD * now.wday + SiD / 2)
when 'monthly'
t = Time.mktime(now.year, now.month, 1) - SiD / 2
else
diff --git a/test/logger/test_logdevice.rb b/test/logger/test_logdevice.rb
index bdd6e35b01..ff39ebde1e 100644
--- a/test/logger/test_logdevice.rb
+++ b/test/logger/test_logdevice.rb
@@ -367,6 +367,49 @@ class TestLogDevice < Test::Unit::TestCase
env_tz_works = /linux|darwin|freebsd/ =~ RUBY_PLATFORM # borrow from test/ruby/test_time_tz.rb
+ def test_shifting_weekly
+ Dir.mktmpdir do |tmpdir|
+ assert_in_out_err([{"TZ"=>"UTC"}, *%W"-rlogger -C#{tmpdir} -"], <<-'end;')
+ begin
+ module FakeTime
+ attr_accessor :now
+ end
+
+ class << Time
+ prepend FakeTime
+ end
+
+ log = "log"
+ File.open(log, "w") {}
+
+ Time.now = Time.utc(2015, 12, 14, 0, 1, 1)
+ dev = Logger::LogDevice.new("log", shift_age: 'weekly')
+
+ Time.now = Time.utc(2015, 12, 19, 12, 34, 56)
+ dev.write("#{Time.now} hello-1\n")
+ File.utime(Time.now, Time.now, log)
+
+ Time.now = Time.utc(2015, 12, 20, 0, 1, 1)
+ File.utime(Time.now, Time.now, log)
+ dev.write("#{Time.now} hello-2\n")
+ ensure
+ dev.close if dev
+ end
+ end;
+ log = File.join(tmpdir, "log")
+ cont = File.read(log)
+ assert_match(/hello-2/, cont)
+ assert_not_match(/hello-1/, cont)
+ log = Dir.glob(log+".*")
+ assert_equal(1, log.size)
+ log, = *log
+ cont = File.read(log)
+ assert_match(/hello-1/, cont)
+ assert_equal("2015-12-19", cont[/^[-\d]+/])
+ assert_equal("20151219", log[/\d+\z/])
+ end
+ end if env_tz_works
+
def test_shifting_dst_change
Dir.mktmpdir do |tmpdir|
assert_in_out_err([{"TZ"=>"Europe/London"}, *%W"--disable=gems -rlogger -C#{tmpdir} -"], <<-'end;')