diff --git a/ChangeLog b/ChangeLog index cfc4380e85..8046d7b6ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun May 25 08:43:16 2014 SHIBATA Hiroshi + + * lib/logger.rb: refactored to include Logger::Period. + Sun May 25 06:50:19 2014 Zachary Scott * vm_eval.c: [DOC] Improve instance_eval description when given a 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 #