From cc0ca767f51f82ea308cb93c6b12e4301a9e4bdf Mon Sep 17 00:00:00 2001 From: hsbt Date: Sat, 24 May 2014 23:54:17 +0000 Subject: * lib/logger.rb: refactored to include Logger::Period. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/logger.rb | 82 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to 'lib/logger.rb') diff --git a/lib/logger.rb b/lib/logger.rb index ca667f48b4..7d76d25e33 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -530,9 +530,48 @@ private end end + module Period + module_function + + SiD = 24 * 60 * 60 + + def next_rotate_time(now, shift_age) + case shift_age + when /^daily$/ + t = Time.mktime(now.year, now.month, now.mday) + SiD + 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) + 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))) + end + t + end + + def previous_period_end(now, shift_age) + case shift_age + 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) + when /^monthly$/ + t = Time.mktime(now.year, now.month, 1) - SiD / 2 + else + return now + end + Time.mktime(t.year, t.month, t.mday, 23, 59, 59) + end + end # Device used for logging messages. class LogDevice + include Period + attr_reader :dev attr_reader :filename @@ -700,49 +739,6 @@ private end end - module Period - module_function - - SiD = 24 * 60 * 60 - - def next_rotate_time(now, shift_age) - case shift_age - when /^daily$/ - t = Time.mktime(now.year, now.month, now.mday) + SiD - 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) - 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))) - end - t - end - - def previous_period_end(now, shift_age) - case shift_age - 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) - when /^monthly$/ - t = Time.mktime(now.year, now.month, 1) - SiD / 2 - else - return now - end - Time.mktime(t.year, t.month, t.mday, 23, 59, 59) - end - end - - class LogDevice - include Period - end - - # # == Description # -- cgit v1.2.3