1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-10-27 03:00:38 +00:00
parent 6160e4b9f4
commit e8c00b7027
3 changed files with 42 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Tue Oct 27 12:00:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@gmail.com>
* test/ruby/test_module.rb (test_method_defined): Add test cases

View file

@ -539,12 +539,14 @@ private
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

View file

@ -365,6 +365,8 @@ class TestLogDevice < Test::Unit::TestCase
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::TestCase
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