[前][次][番号順一覧][スレッド一覧]

ruby-changes:40212

From: nobu <ko1@a...>
Date: Tue, 27 Oct 2015 12:01:20 +0900 (JST)
Subject: [ruby-changes:40212] nobu:r52293 (trunk): logger.rb: fix weekly rotation

nobu	2015-10-27 12:00:38 +0900 (Tue, 27 Oct 2015)

  New Revision: 52293

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52293

  Log:
    logger.rb: fix weekly rotation
    
    * lib/logger.rb (Logger::Period#next_rotate_time): get rid of
      adding to mday not to exceed the days of the month.
      [ruby-core:71185] [Bug #11620]

  Modified files:
    trunk/ChangeLog
    trunk/lib/logger.rb
    trunk/test/logger/test_logdevice.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52292)
+++ ChangeLog	(revision 52293)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 27 12:00:33 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/logger.rb (Logger::Period#next_rotate_time): get rid of
+	  adding to mday not to exceed the days of the month.
+	  [ruby-core:71185] [Bug #11620]
+
 Mon Oct 26 22:43:03 2015  yui-knk  <spiketeika@g...>
 
 	* test/ruby/test_module.rb (test_method_defined): Add test cases
Index: lib/logger.rb
===================================================================
--- lib/logger.rb	(revision 52292)
+++ lib/logger.rb	(revision 52293)
@@ -539,12 +539,14 @@ private https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L539
         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)
+        return Time.mktime(t.year, t.month, 1) if t.mday > 1
       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)))
+      if t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
+        hour = t.hour
+        t = Time.mktime(t.year, t.month, t.mday)
+        t += SiD if hour > 12
       end
       t
     end
Index: test/logger/test_logdevice.rb
===================================================================
--- test/logger/test_logdevice.rb	(revision 52292)
+++ test/logger/test_logdevice.rb	(revision 52293)
@@ -365,6 +365,8 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/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_dst_change
     Dir.mktmpdir do |tmpdir|
       assert_in_out_err([{"TZ"=>"Europe/London"}, *%W"--disable=gems -rlogger -C#{tmpdir} -"], <<-'end;')
@@ -401,7 +403,35 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/logger/test_logdevice.rb#L403
       assert_not_match(/hello-1/, cont)
       assert_file.exist?(log+".20140330")
     end
-  end if /linux|darwin|freebsd/ =~ RUBY_PLATFORM # borrow from test/ruby/test_time_tz.rb
+  end if env_tz_works
+
+  def test_shifting_weekly_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.mktime(2015, 10, 25, 0, 1, 1)
+          dev = Logger::LogDevice.new("log", shift_age: 'weekly')
+          dev.write("#{Time.now} hello-1\n")
+        ensure
+          dev.close if dev
+        end
+      end;
+      log = File.join(tmpdir, "log")
+      cont = File.read(log)
+      assert_match(/hello-1/, cont)
+    end
+  end if env_tz_works
 
   private
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]