ruby-changes:44431
From: usa <ko1@a...>
Date: Thu, 27 Oct 2016 16:47:18 +0900 (JST)
Subject: [ruby-changes:44431] usa:r56504 (ruby_2_2): merge revision(s) 56374: [Backport #12822]
usa 2016-10-27 16:47:14 +0900 (Thu, 27 Oct 2016) New Revision: 56504 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56504 Log: merge revision(s) 56374: [Backport #12822] * lib/logger.rb (Logger::Period#next_rotate_time): fix monthly log rotate when DST is applied during a month of 31 days. [Fix GH-1458] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/lib/logger.rb branches/ruby_2_2/test/logger/test_logdevice.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 56503) +++ ruby_2_2/ChangeLog (revision 56504) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Thu Oct 27 16:39:56 2016 Aurelien Jacobs <aurel@g...> + + * lib/logger.rb (Logger::Period#next_rotate_time): fix monthly log + rotate when DST is applied during a month of 31 days. + [Fix GH-1458] + Thu Oct 27 16:27:06 2016 SHIBATA Hiroshi <hsbt@r...> * object.c: Improve documentation for Float conversion. Index: ruby_2_2/lib/logger.rb =================================================================== --- ruby_2_2/lib/logger.rb (revision 56503) +++ ruby_2_2/lib/logger.rb (revision 56504) @@ -538,8 +538,8 @@ private https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lib/logger.rb#L538 when /^weekly$/ t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday) when /^monthly$/ - t = Time.mktime(now.year, now.month, 1) + SiD * 31 - mday = (1 if t.mday > 1) + t = Time.mktime(now.year, now.month, 1) + SiD * 32 + mday = 1 else return now end Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 56503) +++ ruby_2_2/version.h (revision 56504) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-10-27" -#define RUBY_PATCHLEVEL 382 +#define RUBY_PATCHLEVEL 383 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 10 Index: ruby_2_2/test/logger/test_logdevice.rb =================================================================== --- ruby_2_2/test/logger/test_logdevice.rb (revision 56503) +++ ruby_2_2/test/logger/test_logdevice.rb (revision 56504) @@ -365,6 +365,51 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/logger/test_logdevice.rb#L365 end end + env_tz_works = /linux|darwin|freebsd/ =~ RUBY_PLATFORM # borrow from test/ruby/test_time_tz.rb + + def test_shifting_monthly + 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: 'monthly') + + Time.now = Time.utc(2015, 12, 31, 12, 34, 56) + dev.write("#{Time.now} hello-1\n") + File.utime(Time.now, Time.now, log) + + Time.now = Time.utc(2016, 1, 1, 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-31", cont[/^[-\d]+/]) + assert_equal("20151231", 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;') @@ -403,6 +448,53 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/logger/test_logdevice.rb#L448 end end if /linux|darwin|freebsd/ =~ RUBY_PLATFORM # borrow from test/ruby/test_time_tz.rb + def test_shifting_monthly_dst_change + Dir.mktmpdir do |tmpdir| + assert_separately([{"TZ"=>"Europe/London"}, *%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(2016, 9, 1, 0, 1, 1) + dev = Logger::LogDevice.new("log", shift_age: 'monthly') + + Time.now = Time.utc(2016, 9, 8, 7, 6, 5) + dev.write("#{Time.now} hello-1\n") + File.utime(Time.now, Time.now, log) + + Time.now = Time.utc(2016, 10, 9, 8, 7, 6) + File.utime(Time.now, Time.now, log) + dev.write("#{Time.now} hello-2\n") + + Time.now = Time.utc(2016, 10, 9, 8, 7, 7) + File.utime(Time.now, Time.now, log) + dev.write("#{Time.now} hello-3\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("2016-09-08", cont[/^[-\d]+/]) + assert_equal("20160930", log[/\d+\z/]) + end + end if env_tz_works + private def run_children(n, args, src) Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r56374 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/