logging 1.6.0 → 1.6.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.
- data/History.txt +7 -1
- data/lib/logging.rb +3 -1
- data/lib/logging/appenders/rolling_file.rb +2 -2
- data/lib/logging/rails_compat.rb +33 -0
- data/lib/logging/utils.rb +26 -0
- data/test/appenders/test_rolling_file.rb +31 -0
- data/version.txt +1 -1
- metadata +13 -12
data/History.txt
CHANGED
data/lib/logging.rb
CHANGED
@@ -529,6 +529,8 @@ Logging.libpath {
|
|
529
529
|
|
530
530
|
require 'logging/config/configurator'
|
531
531
|
require 'logging/config/yaml_configurator'
|
532
|
+
|
533
|
+
require 'logging/rails_compat'
|
532
534
|
}
|
533
535
|
|
534
536
|
|
@@ -536,7 +538,7 @@ Logging.libpath {
|
|
536
538
|
# This is needed for closing IO streams and connections to the syslog server
|
537
539
|
# or e-mail servers, etc.
|
538
540
|
#
|
539
|
-
at_exit {Logging.shutdown}
|
541
|
+
at_exit { Logging.shutdown }
|
540
542
|
|
541
543
|
end # unless defined?
|
542
544
|
|
@@ -205,7 +205,7 @@ module Logging::Appenders
|
|
205
205
|
# Returns +true+ if the log file needs to be rolled.
|
206
206
|
#
|
207
207
|
def roll_required?
|
208
|
-
return false if ::File.exist? @fn_copy
|
208
|
+
return false if ::File.exist?(@fn_copy) and (Time.now - ::File.mtime(@fn_copy)) < 180
|
209
209
|
|
210
210
|
# check if max size has been exceeded
|
211
211
|
s = @size ? ::File.size(@fn) > @size : false
|
@@ -222,7 +222,7 @@ module Logging::Appenders
|
|
222
222
|
#
|
223
223
|
def copy_truncate
|
224
224
|
return unless ::File.exist?(@fn)
|
225
|
-
FileUtils.
|
225
|
+
FileUtils.concat @fn, @fn_copy
|
226
226
|
@io.truncate 0
|
227
227
|
|
228
228
|
# touch the age file if needed
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
if defined? ActiveSupport
|
3
|
+
|
4
|
+
module Logging
|
5
|
+
|
6
|
+
# Rails compatibility module.
|
7
|
+
#
|
8
|
+
# The ActiveSupport gem adds a few methods to the default Ruby logger, and
|
9
|
+
# some Rails extensions expect these methods to exist. Those methods are
|
10
|
+
# implemented in this module and included in the Logging::Logger class when
|
11
|
+
# the ActiveSupport gem is present.
|
12
|
+
#
|
13
|
+
module RailsCompat
|
14
|
+
|
15
|
+
# A no-op implementation of the +silence+ method. Setting of log levels
|
16
|
+
# should be done during the Logging configuration. It is the author's
|
17
|
+
# opinion that overriding the log level programmaticaly is a logical
|
18
|
+
# error.
|
19
|
+
#
|
20
|
+
# Please see https://github.com/TwP/logging/issues/11 for a more detail
|
21
|
+
# discussion of the issue.
|
22
|
+
#
|
23
|
+
def silence( *args )
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
|
27
|
+
end # RailsCompat
|
28
|
+
|
29
|
+
Logger.send :include, RailsCompat
|
30
|
+
|
31
|
+
end # Logging
|
32
|
+
end # if defined?
|
33
|
+
|
data/lib/logging/utils.rb
CHANGED
@@ -174,6 +174,32 @@ class File
|
|
174
174
|
|
175
175
|
end
|
176
176
|
|
177
|
+
# --------------------------------------------------------------------------
|
178
|
+
module FileUtils
|
179
|
+
|
180
|
+
# Concatenate the contents of the _src_ file to the end of the _dest_ file.
|
181
|
+
# If the _dest_ file does not exist, then the _src_ file is copied to the
|
182
|
+
# _dest_ file using +copy_file+.
|
183
|
+
#
|
184
|
+
def concat( src, dest )
|
185
|
+
if File.exist?(dest)
|
186
|
+
bufsize = File.stat(dest).blksize || 8192
|
187
|
+
buffer = String.new
|
188
|
+
|
189
|
+
File.open(dest, 'a') { |d|
|
190
|
+
File.open(src, 'r') { |r|
|
191
|
+
while bytes = r.read(bufsize, buffer)
|
192
|
+
d.syswrite bytes
|
193
|
+
end
|
194
|
+
}
|
195
|
+
}
|
196
|
+
else
|
197
|
+
copy_file(src, dest)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
module_function :concat
|
201
|
+
end
|
202
|
+
|
177
203
|
# --------------------------------------------------------------------------
|
178
204
|
class ReentrantMutex < Mutex
|
179
205
|
|
@@ -211,6 +211,37 @@ module TestAppenders
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
|
+
def test_stale_copy_file
|
215
|
+
ap = Logging.appenders.rolling_file(NAME, :filename => @fn, :size => 100)
|
216
|
+
|
217
|
+
fn_copy = @fn + '._copy_'
|
218
|
+
File.open(fn_copy, 'w') { |copy| copy.puts 'stale copy file' }
|
219
|
+
|
220
|
+
ap << 'X' * 100; ap.flush
|
221
|
+
assert_equal 1, Dir.glob(@glob).length
|
222
|
+
assert_equal 100, File.size(@fn)
|
223
|
+
|
224
|
+
# this character is appended to the log file (bringing its size to 101)
|
225
|
+
# but the file is NOT ROLLED because the _copy_ file is in the way
|
226
|
+
ap << 'X'
|
227
|
+
assert_equal 1, Dir.glob(@glob).length
|
228
|
+
assert_equal 101, File.size(@fn)
|
229
|
+
assert_equal 16, File.size(fn_copy)
|
230
|
+
|
231
|
+
# if the _copy_ file is older than three minutes, it will be
|
232
|
+
# concatenated to and moved out of the way
|
233
|
+
time = Time.now - 200
|
234
|
+
::File.utime(time, time, fn_copy)
|
235
|
+
|
236
|
+
ap << 'X'
|
237
|
+
assert_equal 2, Dir.glob(@glob).length
|
238
|
+
assert_equal 0, File.size(@fn)
|
239
|
+
assert_equal 118, File.size(Dir.glob(@glob).sort.first)
|
240
|
+
assert !File.exist?(fn_copy), '_copy_ file should not exist'
|
241
|
+
|
242
|
+
cleanup
|
243
|
+
end
|
244
|
+
|
214
245
|
private
|
215
246
|
def cleanup
|
216
247
|
unless Logging.appenders[NAME].nil?
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: little-plugger
|
16
|
-
requirement: &
|
16
|
+
requirement: &2162102160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.1.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2162102160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: flexmock
|
27
|
-
requirement: &
|
27
|
+
requirement: &2162101340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2162101340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bones-git
|
38
|
-
requirement: &
|
38
|
+
requirement: &2162100820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.2.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2162100820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bones-rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &2162100100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2162100100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bones
|
60
|
-
requirement: &
|
60
|
+
requirement: &2162099500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 3.7.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2162099500
|
69
69
|
description: ! 'Logging is a flexible logging library for use in Ruby programs based
|
70
70
|
on the
|
71
71
|
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/logging/log_event.rb
|
124
124
|
- lib/logging/logger.rb
|
125
125
|
- lib/logging/proxy.rb
|
126
|
+
- lib/logging/rails_compat.rb
|
126
127
|
- lib/logging/repository.rb
|
127
128
|
- lib/logging/root_logger.rb
|
128
129
|
- lib/logging/stats.rb
|