evanescent 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/evanescent.rb +27 -5
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff1e9e7823c63c657230fa20dd406dacb2897c0
4
- data.tar.gz: ccc22b1ec8761409e924d053b1aa3922fb3df822
3
+ metadata.gz: b5c0460154818ebb24936f927d692124020c8556
4
+ data.tar.gz: 66225a80f1f380b06bb869da37355e09e7d40599
5
5
  SHA512:
6
- metadata.gz: 148420dc06bc9e69b70e402b12f22119e63166b146c057811c34c461cef9cd86dbbb047f2d75a88ed9a5ff02efbdc2b1bae17341733aa597dd5614c15a6a80c0
7
- data.tar.gz: a46387fccc6656c52639775dcfad5603eb7e8ac03ab73d5afb247312ed15aba58f831e57764d6f362028e3c0a2046676151bcc9b46ec8d1f8bf12100df0fcfbb
6
+ metadata.gz: f901c5efbfac38bb3309865cde45c2f67dc1d1c4e4682fca6900d905a36b2d396ceca8a36b1118f3f7526e106eb6499e9b69b1a1b3e9ba9bdf1b50e77bf97d06
7
+ data.tar.gz: b9b058a9cedd08d98b70e2a4a9e3971d765a19f23e98812ac620cb5a5fc188b72bddbeadae7ee90c091b2b7730c7cd7e35c2cc85820f2ef706b35a435dd79c7d
data/lib/evanescent.rb CHANGED
@@ -74,11 +74,13 @@ class Evanescent
74
74
  PARAMS = {
75
75
  hourly: {
76
76
  strftime: '%Y%m%d%H',
77
- glob: '[0-9]' * (4 + 2 * 3)
77
+ glob: '[0-9]' * (4 + 2 * 3),
78
+ interval: 3600
78
79
  },
79
80
  daily: {
80
81
  strftime: '%Y%m%d',
81
- glob: '[0-9]' * (4 + 2 * 2)
82
+ glob: '[0-9]' * (4 + 2 * 2),
83
+ interval: 3600 * 24
82
84
  }
83
85
  }
84
86
 
@@ -87,17 +89,37 @@ class Evanescent
87
89
  end
88
90
 
89
91
  def rotate
92
+ if @io
93
+ rotate_with_open_io
94
+ else
95
+ rotate_with_closed_io
96
+ end
97
+ end
98
+
99
+ def rotate_with_open_io
90
100
  curr_suffix = make_prefix(Time.now)
91
101
  return if curr_suffix == @last_prefix
92
102
  @io.close
93
103
  @io = nil
94
- rotated = "#{path}.#{curr_suffix}"
104
+ do_rotation("#{path}.#{curr_suffix}")
105
+ @last_prefix = curr_suffix
106
+ end
107
+
108
+ def rotate_with_closed_io
109
+ return unless File.exist?(path)
110
+ curr_suffix = make_prefix(Time.now+PARAMS[rotation][:interval])
111
+ rotation_suffix = make_prefix(File.mtime(path) + PARAMS[rotation][:interval])
112
+ return if curr_suffix == rotation_suffix
113
+ do_rotation("#{path}.#{rotation_suffix}")
114
+ @last_prefix = curr_suffix
115
+ end
116
+
117
+ def do_rotation new_path
95
118
  begin
96
- FileUtils.mv(path, rotated)
119
+ FileUtils.mv(path, new_path)
97
120
  rescue
98
121
  warn("Error renaming '#{path}' to '#{rotated}': #{$!}")
99
122
  end
100
- @last_prefix = curr_suffix
101
123
  end
102
124
 
103
125
  def compress
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evanescent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Pugliese Ornellas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic_duration
@@ -112,12 +112,12 @@ dependencies:
112
112
  - - "~>"
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0.8'
115
- description: |-
116
- This gem provides an IO like object, that can be used with any logging class (such as Ruby's native Logger). This object will save its input to a file, and allows:
117
- * Rotation by time / date.
118
- * Compression of old files.
119
- * Removal of old compressed files.
120
- Its purpuse is to supplement logging classes, allowing everything related to logging management, to be done within Ruby, without relying on external tools (such as logrotate).
115
+ description: 'This gem provides an IO like object, that can be used with any logging
116
+ class (such as Ruby''s native Logger). This object will save its input to a file,
117
+ and allows: rotation by time / date, compression of old files and removal of old
118
+ compressed files. Its purpuse is to supplement logging classes, allowing everything
119
+ related to logging management, to be done within Ruby, without relying on external
120
+ tools (such as logrotate).'
121
121
  email: fabio.ornellas@gmail.com
122
122
  executables: []
123
123
  extensions: []