ruby-changes:40216
From: nobu <ko1@a...>
Date: Tue, 27 Oct 2015 16:18:26 +0900 (JST)
Subject: [ruby-changes:40216] nobu:r52297 (trunk): logger.rb: end of week should be Saturday
nobu 2015-10-27 16:18:14 +0900 (Tue, 27 Oct 2015) New Revision: 52297 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52297 Log: 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] Modified files: trunk/ChangeLog trunk/lib/logger.rb trunk/test/logger/test_logdevice.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52296) +++ ChangeLog (revision 52297) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Oct 27 16:18:12 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * vm_dump.c (rb_print_backtrace): our addr2line doesn't work on sparc. Index: lib/logger.rb =================================================================== --- lib/logger.rb (revision 52296) +++ lib/logger.rb (revision 52297) @@ -556,7 +556,7 @@ private https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L556 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 Index: test/logger/test_logdevice.rb =================================================================== --- test/logger/test_logdevice.rb (revision 52296) +++ test/logger/test_logdevice.rb (revision 52297) @@ -367,6 +367,49 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/logger/test_logdevice.rb#L367 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;') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/