diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-24 23:54:17 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-24 23:54:17 +0000 |
commit | cc0ca767f51f82ea308cb93c6b12e4301a9e4bdf (patch) | |
tree | 1a37022b25be6bbe3c80df78060ec5747dd4ab3e /lib | |
parent | 602f7b5d8267519d910614bb099f96e432b467b7 (diff) | |
download | ruby-cc0ca767f51f82ea308cb93c6b12e4301a9e4bdf.tar.gz |
* 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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/logger.rb | 82 |
1 files changed, 39 insertions, 43 deletions
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 # |