зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
17e5dff210
Коммит
6df21cb469
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;')
|
||||
|
|
Загрузка…
Ссылка в новой задаче