evanescent 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/evanescent.rb +43 -24
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff1e9e7823c63c657230fa20dd406dacb2897c0
|
4
|
+
data.tar.gz: ccc22b1ec8761409e924d053b1aa3922fb3df822
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148420dc06bc9e69b70e402b12f22119e63166b146c057811c34c461cef9cd86dbbb047f2d75a88ed9a5ff02efbdc2b1bae17341733aa597dd5614c15a6a80c0
|
7
|
+
data.tar.gz: a46387fccc6656c52639775dcfad5603eb7e8ac03ab73d5afb247312ed15aba58f831e57764d6f362028e3c0a2046676151bcc9b46ec8d1f8bf12100df0fcfbb
|
data/lib/evanescent.rb
CHANGED
@@ -27,7 +27,8 @@ class Evanescent
|
|
27
27
|
@keep = ChronicDuration.parse(opts[:keep])
|
28
28
|
@mutex = Mutex.new
|
29
29
|
@last_prefix = make_prefix(Time.now)
|
30
|
-
|
30
|
+
@io = nil
|
31
|
+
@compress_thread = nil
|
31
32
|
end
|
32
33
|
|
33
34
|
# Writes to #path and rotate, compress and purge if necessary.
|
@@ -36,6 +37,7 @@ class Evanescent
|
|
36
37
|
rotate
|
37
38
|
compress
|
38
39
|
purge
|
40
|
+
open_io
|
39
41
|
@io.write(string)
|
40
42
|
end
|
41
43
|
end
|
@@ -47,11 +49,26 @@ class Evanescent
|
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
52
|
+
# Compression is done in a separate thread. Thus method suspends current thread execution until existing compression thread returns. If no compression thread is running, returns immediately.
|
53
|
+
def wait_compression
|
54
|
+
if @compress_thread
|
55
|
+
begin
|
56
|
+
@compress_thread.join
|
57
|
+
rescue
|
58
|
+
warn("Compression thread failed: #{$!}")
|
59
|
+
ensure
|
60
|
+
@compress_thread = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
50
65
|
private
|
51
66
|
|
52
|
-
def
|
53
|
-
@io
|
54
|
-
|
67
|
+
def open_io
|
68
|
+
unless @io
|
69
|
+
@io = File.open(path, File::APPEND | File::CREAT | File::WRONLY)
|
70
|
+
@io.sync = true
|
71
|
+
end
|
55
72
|
end
|
56
73
|
|
57
74
|
PARAMS = {
|
@@ -71,33 +88,35 @@ class Evanescent
|
|
71
88
|
|
72
89
|
def rotate
|
73
90
|
curr_suffix = make_prefix(Time.now)
|
74
|
-
if curr_suffix
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
open_file
|
83
|
-
@last_prefix = curr_suffix
|
91
|
+
return if curr_suffix == @last_prefix
|
92
|
+
@io.close
|
93
|
+
@io = nil
|
94
|
+
rotated = "#{path}.#{curr_suffix}"
|
95
|
+
begin
|
96
|
+
FileUtils.mv(path, rotated)
|
97
|
+
rescue
|
98
|
+
warn("Error renaming '#{path}' to '#{rotated}': #{$!}")
|
84
99
|
end
|
100
|
+
@last_prefix = curr_suffix
|
85
101
|
end
|
86
102
|
|
87
103
|
def compress
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
104
|
+
wait_compression
|
105
|
+
@compress_thread = Thread.new do
|
106
|
+
Dir.glob("#{path}.#{PARAMS[rotation][:glob]}").each do |uncompressed|
|
107
|
+
compressed = "#{uncompressed}.gz"
|
108
|
+
Zlib::GzipWriter.open(compressed) do |gz|
|
109
|
+
gz.mtime = File.mtime(uncompressed)
|
110
|
+
gz.orig_name = uncompressed
|
111
|
+
File.open(uncompressed, 'r') do |io|
|
112
|
+
io.binmode
|
113
|
+
io.each do |data|
|
114
|
+
gz.write(data)
|
115
|
+
end
|
97
116
|
end
|
98
117
|
end
|
118
|
+
File.delete(uncompressed)
|
99
119
|
end
|
100
|
-
File.delete(uncompressed)
|
101
120
|
end
|
102
121
|
rescue
|
103
122
|
warn("Error compressing files: #{$!}")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evanescent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Pugliese Ornellas
|
@@ -144,8 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.4.5
|
147
|
+
rubygems_version: 2.4.5.1
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: IO like object that allows logging rotation, compression and purging.
|
151
151
|
test_files: []
|
152
|
+
has_rdoc:
|