logging 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +13 -0
- data/History.txt +10 -0
- data/README.rdoc +24 -3
- data/Rakefile +2 -2
- data/lib/logging.rb +23 -23
- data/lib/logging/appender.rb +9 -6
- data/lib/logging/appenders.rb +12 -84
- data/lib/logging/appenders/buffering.rb +2 -2
- data/lib/logging/appenders/console.rb +22 -4
- data/lib/logging/appenders/email.rb +166 -61
- data/lib/logging/appenders/file.rb +9 -2
- data/lib/logging/appenders/growl.rb +12 -8
- data/lib/logging/appenders/io.rb +9 -2
- data/lib/logging/appenders/rolling_file.rb +9 -2
- data/lib/logging/appenders/string_io.rb +9 -2
- data/lib/logging/appenders/syslog.rb +9 -3
- data/lib/logging/layouts.rb +5 -42
- data/lib/logging/layouts/basic.rb +7 -0
- data/lib/logging/layouts/parseable.rb +18 -0
- data/lib/logging/layouts/pattern.rb +7 -0
- data/lib/logging/proxy.rb +2 -0
- data/lib/logging/utils.rb +3 -1
- data/test/appenders/test_buffered_io.rb +0 -1
- data/test/appenders/test_console.rb +0 -1
- data/test/appenders/test_email.rb +14 -14
- data/test/appenders/test_growl.rb +14 -3
- data/test/appenders/test_io.rb +0 -1
- data/test/appenders/test_periodic_flushing.rb +2 -1
- data/test/appenders/test_syslog.rb +0 -1
- data/test/benchmark.rb +0 -1
- data/test/config/test_configurator.rb +0 -1
- data/test/config/test_yaml_configurator.rb +0 -1
- data/test/layouts/test_basic.rb +0 -1
- data/test/layouts/test_json.rb +0 -1
- data/test/layouts/test_yaml.rb +0 -1
- data/test/test_appender.rb +0 -1
- data/test/test_consolidate.rb +0 -1
- data/test/test_layout.rb +0 -1
- data/test/test_log_event.rb +0 -1
- data/test/test_logger.rb +0 -1
- data/test/test_logging.rb +1 -2
- data/test/test_proxy.rb +6 -0
- data/test/test_repository.rb +0 -1
- data/test/test_root_logger.rb +0 -1
- data/test/test_stats.rb +0 -1
- data/test/test_utils.rb +1 -2
- data/version.txt +1 -1
- metadata +11 -21
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Appenders
|
3
3
|
|
4
|
+
# Accessor / Factory for the File appender.
|
5
|
+
#
|
6
|
+
def self.file( *args )
|
7
|
+
return ::Logging::Appenders::File if args.empty?
|
8
|
+
::Logging::Appenders::File.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# This class provides an Appender that can write to a File.
|
5
12
|
#
|
6
13
|
class File < ::Logging::Appenders::IO
|
@@ -70,6 +77,6 @@ module Logging::Appenders
|
|
70
77
|
self
|
71
78
|
end
|
72
79
|
|
73
|
-
end #
|
74
|
-
end #
|
80
|
+
end # FileAppender
|
81
|
+
end # Logging::Appenders
|
75
82
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Appenders
|
3
3
|
|
4
|
+
# Accessor / Factory for the Growl appender.
|
5
|
+
#
|
6
|
+
def self.growl( *args )
|
7
|
+
return ::Logging::Appenders::Growl if args.empty?
|
8
|
+
::Logging::Appenders::Growl.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# This class provides an Appender that can send notifications to the Growl
|
5
12
|
# notification system on Mac OS X.
|
6
13
|
#
|
@@ -67,7 +74,7 @@ module Logging::Appenders
|
|
67
74
|
end
|
68
75
|
|
69
76
|
|
70
|
-
|
77
|
+
private
|
71
78
|
|
72
79
|
# call-seq:
|
73
80
|
# write( event )
|
@@ -150,8 +157,6 @@ module Logging::Appenders
|
|
150
157
|
end
|
151
158
|
end
|
152
159
|
end
|
153
|
-
|
154
|
-
Thread.pass
|
155
160
|
end
|
156
161
|
|
157
162
|
# call-seq:
|
@@ -167,13 +172,12 @@ module Logging::Appenders
|
|
167
172
|
@c_queue = []
|
168
173
|
|
169
174
|
@c_thread = Thread.new do
|
170
|
-
Thread.stop
|
171
175
|
loop do
|
172
|
-
|
176
|
+
Thread.stop if @c_queue.empty?
|
177
|
+
sleep 1
|
173
178
|
@c_mutex.synchronize {
|
174
179
|
call_growl(*@c_queue.shift) until @c_queue.empty?
|
175
180
|
}
|
176
|
-
Thread.stop if @c_queue.empty?
|
177
181
|
end # loop
|
178
182
|
end # Thread.new
|
179
183
|
end
|
@@ -191,6 +195,6 @@ module Logging::Appenders
|
|
191
195
|
end
|
192
196
|
end
|
193
197
|
|
194
|
-
end #
|
195
|
-
end #
|
198
|
+
end # Growl
|
199
|
+
end # Logging::Appenders
|
196
200
|
|
data/lib/logging/appenders/io.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Appenders
|
3
3
|
|
4
|
+
# Accessor / Factory for the IO appender.
|
5
|
+
#
|
6
|
+
def self.io( *args )
|
7
|
+
return ::Logging::Appenders::IO if args.empty?
|
8
|
+
::Logging::Appenders::IO.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# This class provides an Appender that can write to any IO stream
|
5
12
|
# configured for writing.
|
6
13
|
#
|
@@ -70,6 +77,6 @@ module Logging::Appenders
|
|
70
77
|
::Logging.log_internal(-2) {err}
|
71
78
|
end
|
72
79
|
|
73
|
-
end #
|
74
|
-
end #
|
80
|
+
end # IO
|
81
|
+
end # Logging::Appenders
|
75
82
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Appenders
|
3
3
|
|
4
|
+
# Accessor / Factory for the RollingFile appender.
|
5
|
+
#
|
6
|
+
def self.rolling_file( *args )
|
7
|
+
return ::Logging::Appenders::RollingFile if args.empty?
|
8
|
+
::Logging::Appenders::RollingFile.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# An appender that writes to a file and ensures that the file size or age
|
5
12
|
# never exceeds some user specified level.
|
6
13
|
#
|
@@ -324,6 +331,6 @@ module Logging::Appenders
|
|
324
331
|
end
|
325
332
|
# :startdoc:
|
326
333
|
|
327
|
-
end #
|
328
|
-
end #
|
334
|
+
end # RollingFile
|
335
|
+
end # Logging::Appenders
|
329
336
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Appenders
|
3
3
|
|
4
|
+
# Accessor / Factory for the StringIo appender.
|
5
|
+
#
|
6
|
+
def self.string_io( *args )
|
7
|
+
return ::Logging::Appenders::StringIo if args.empty?
|
8
|
+
::Logging::Appenders::StringIo.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# This class provides an Appender that can write to a StringIO instance.
|
5
12
|
# This is very useful for testing log message output.
|
6
13
|
#
|
@@ -80,6 +87,6 @@ module Logging::Appenders
|
|
80
87
|
end
|
81
88
|
# :startdoc:
|
82
89
|
|
83
|
-
end #
|
84
|
-
end #
|
90
|
+
end # StringIo
|
91
|
+
end # Logging::Appenders
|
85
92
|
|
@@ -6,6 +6,13 @@ if HAVE_SYSLOG
|
|
6
6
|
|
7
7
|
module Logging::Appenders
|
8
8
|
|
9
|
+
# Accessor / Factory for the Syslog appender.
|
10
|
+
#
|
11
|
+
def self.syslog( *args )
|
12
|
+
return ::Logging::Appenders::Syslog if args.empty?
|
13
|
+
::Logging::Appenders::Syslog.new(*args)
|
14
|
+
end
|
15
|
+
|
9
16
|
# This class provides an Appender that can write to the UNIX syslog
|
10
17
|
# daemon.
|
11
18
|
#
|
@@ -202,8 +209,7 @@ module Logging::Appenders
|
|
202
209
|
end
|
203
210
|
end
|
204
211
|
|
205
|
-
end #
|
206
|
-
|
207
|
-
end # module Logging::Appenders
|
212
|
+
end # Syslog
|
213
|
+
end # Logging::Appenders
|
208
214
|
end # HAVE_SYSLOG
|
209
215
|
|
data/lib/logging/layouts.rb
CHANGED
@@ -1,46 +1,9 @@
|
|
1
1
|
|
2
2
|
module Logging
|
3
|
-
module Layouts
|
3
|
+
module Layouts; end
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
::Logging::Layouts::Basic.new(*args)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Accessor / Factory for the Pattern layout.
|
13
|
-
#
|
14
|
-
def pattern( *args )
|
15
|
-
return ::Logging::Layouts::Pattern if args.empty?
|
16
|
-
::Logging::Layouts::Pattern.new(*args)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Accessor for the Parseable layout.
|
20
|
-
#
|
21
|
-
def parseable
|
22
|
-
::Logging::Layouts::Parseable
|
23
|
-
end
|
24
|
-
|
25
|
-
# Factory for the Parseable layout using JSON formatting.
|
26
|
-
#
|
27
|
-
def json( *args )
|
28
|
-
::Logging::Layouts::Parseable.json(*args)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Factory for the Parseable layout using YAML formatting.
|
32
|
-
#
|
33
|
-
def yaml( *args )
|
34
|
-
::Logging::Layouts::Parseable.yaml(*args)
|
35
|
-
end
|
36
|
-
|
37
|
-
extend self
|
38
|
-
end # module Layouts
|
39
|
-
end # module Logging
|
40
|
-
|
41
|
-
Logging.libpath {
|
42
|
-
require 'logging/layouts/basic'
|
43
|
-
require 'logging/layouts/parseable'
|
44
|
-
require 'logging/layouts/pattern'
|
45
|
-
}
|
5
|
+
require libpath('logging/layouts/basic')
|
6
|
+
require libpath('logging/layouts/parseable')
|
7
|
+
require libpath('logging/layouts/pattern')
|
8
|
+
end # Logging
|
46
9
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Layouts
|
3
3
|
|
4
|
+
# Accessor / Factory for the Basic layout.
|
5
|
+
#
|
6
|
+
def self.basic( *args )
|
7
|
+
return ::Logging::Layouts::Basic if args.empty?
|
8
|
+
::Logging::Layouts::Basic.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# The +Basic+ layout class provides methods for simple formatting of log
|
5
12
|
# events. The resulting string follows the format below.
|
6
13
|
#
|
@@ -1,6 +1,24 @@
|
|
1
1
|
|
2
2
|
module Logging::Layouts
|
3
3
|
|
4
|
+
# Accessor for the Parseable layout.
|
5
|
+
#
|
6
|
+
def self.parseable
|
7
|
+
::Logging::Layouts::Parseable
|
8
|
+
end
|
9
|
+
|
10
|
+
# Factory for the Parseable layout using JSON formatting.
|
11
|
+
#
|
12
|
+
def self.json( *args )
|
13
|
+
::Logging::Layouts::Parseable.json(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Factory for the Parseable layout using YAML formatting.
|
17
|
+
#
|
18
|
+
def self.yaml( *args )
|
19
|
+
::Logging::Layouts::Parseable.yaml(*args)
|
20
|
+
end
|
21
|
+
|
4
22
|
# This layout will produce parseable log output in either JSON or YAML
|
5
23
|
# format. This makes it much easier for machines to parse log files and
|
6
24
|
# perform analysis on those logs.
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
module Logging::Layouts
|
3
3
|
|
4
|
+
# Accessor / Factory for the Pattern layout.
|
5
|
+
#
|
6
|
+
def self.pattern( *args )
|
7
|
+
return ::Logging::Layouts::Pattern if args.empty?
|
8
|
+
::Logging::Layouts::Pattern.new(*args)
|
9
|
+
end
|
10
|
+
|
4
11
|
# A flexible layout configurable with pattern string.
|
5
12
|
#
|
6
13
|
# The goal of this class is to format a LogEvent and return the results as
|
data/lib/logging/proxy.rb
CHANGED
@@ -33,6 +33,8 @@ module Logging
|
|
33
33
|
# replace the +method_missing+ implementation
|
34
34
|
#
|
35
35
|
def initialize( object, &block )
|
36
|
+
Kernel.raise ArgumentError, "Cannot proxy nil" if nil.equal? object
|
37
|
+
|
36
38
|
@object = object
|
37
39
|
@leader = @object.is_a?(Class) ? "#{@object.name}." : "#{@object.class.name}#"
|
38
40
|
@logger = Logging.logger[object]
|
data/lib/logging/utils.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'thread'
|
3
|
+
require 'rbconfig'
|
3
4
|
|
4
5
|
# --------------------------------------------------------------------------
|
5
6
|
class Hash
|
@@ -165,7 +166,8 @@ class File
|
|
165
166
|
end
|
166
167
|
|
167
168
|
# :stopdoc:
|
168
|
-
if
|
169
|
+
if Config::CONFIG['host_os'] =~ /mswin|windows|cygwin/i
|
170
|
+
# don't lock files on windows
|
169
171
|
undef :flock?, :flock_sh
|
170
172
|
def flock?() yield; end
|
171
173
|
def flock_sh() yield; end
|
@@ -14,14 +14,14 @@ module TestAppenders
|
|
14
14
|
|
15
15
|
flexmock(Net::SMTP).new_instances do |m|
|
16
16
|
m.should_receive(:start).at_least.once.with(
|
17
|
-
'test.logging', 'test', 'test', :
|
17
|
+
'test.logging', 'test', 'test', :plain, Proc).and_yield(m)
|
18
18
|
m.should_receive(:sendmail).at_least.once.with(String, 'me', ['you'])
|
19
19
|
end
|
20
20
|
|
21
21
|
@appender = Logging.appenders.email('email',
|
22
22
|
'from' => 'me', 'to' => 'you',
|
23
23
|
:buffer_size => '3', :immediate_at => 'error, fatal',
|
24
|
-
:domain => 'test.logging', :
|
24
|
+
:domain => 'test.logging', :user_name => 'test', :password => 'test'
|
25
25
|
)
|
26
26
|
@levels = Logging::LEVELS
|
27
27
|
end
|
@@ -43,35 +43,36 @@ module TestAppenders
|
|
43
43
|
|
44
44
|
assert_equal(100, appender.auto_flushing)
|
45
45
|
assert_equal([], appender.instance_variable_get(:@immediate))
|
46
|
-
assert_equal('localhost', appender.
|
46
|
+
assert_equal('localhost', appender.address)
|
47
47
|
assert_equal(25, appender.port)
|
48
48
|
|
49
49
|
domain = ENV['HOSTNAME'] || 'localhost.localdomain'
|
50
50
|
assert_equal(domain, appender.domain)
|
51
|
-
assert_equal(nil, appender.
|
52
|
-
assert_equal(:
|
53
|
-
assert_equal("Message
|
51
|
+
assert_equal(nil, appender.user_name)
|
52
|
+
assert_equal(:plain, appender.authentication)
|
53
|
+
assert_equal("Message from #{$0}", appender.subject)
|
54
54
|
|
55
55
|
appender = Logging.appenders.email('email',
|
56
56
|
'from' => 'lbrinn@gmail.com', 'to' => 'everyone',
|
57
57
|
:buffsize => '1000', :immediate_at => 'error, fatal',
|
58
|
-
:
|
59
|
-
:domain => 'google.com', :
|
60
|
-
:
|
58
|
+
:address => 'smtp.google.com', :port => '443',
|
59
|
+
:domain => 'google.com', :user_name => 'lbrinn',
|
60
|
+
:password => '1234', :authentication => 'plain', :enable_starttls_auto => true,
|
61
61
|
:subject => "I'm rich and you're not"
|
62
62
|
)
|
63
63
|
|
64
64
|
assert_equal('lbrinn@gmail.com', appender.instance_variable_get(:@from))
|
65
65
|
assert_equal(['everyone'], appender.instance_variable_get(:@to))
|
66
66
|
assert_equal(1000, appender.auto_flushing)
|
67
|
-
assert_equal('1234', appender.
|
67
|
+
assert_equal('1234', appender.password)
|
68
68
|
assert_equal([nil, nil, nil, true, true],
|
69
69
|
appender.instance_variable_get(:@immediate))
|
70
|
-
assert_equal('smtp.google.com', appender.
|
70
|
+
assert_equal('smtp.google.com', appender.address)
|
71
71
|
assert_equal(443, appender.port)
|
72
72
|
assert_equal('google.com', appender.domain)
|
73
|
-
assert_equal('lbrinn', appender.
|
74
|
-
assert_equal(:
|
73
|
+
assert_equal('lbrinn', appender.user_name)
|
74
|
+
assert_equal(:plain, appender.authentication)
|
75
|
+
assert(appender.enable_starttls_auto)
|
75
76
|
assert_equal("I'm rich and you're not", appender.subject)
|
76
77
|
|
77
78
|
appender = Logging.appenders.email('email',
|
@@ -167,4 +168,3 @@ module TestAppenders
|
|
167
168
|
end # module TestLogging
|
168
169
|
end # module TestAppenders
|
169
170
|
|
170
|
-
# EOF
|
@@ -48,7 +48,7 @@ module TestAppenders
|
|
48
48
|
@appender.append info
|
49
49
|
@appender.append info
|
50
50
|
@appender.append warn
|
51
|
-
|
51
|
+
ensure_queue_is_empty
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_append_without_coalescing
|
@@ -70,7 +70,7 @@ module TestAppenders
|
|
70
70
|
@appender << 'first message'
|
71
71
|
@appender << 'second message'
|
72
72
|
@appender << 'third message'
|
73
|
-
|
73
|
+
ensure_queue_is_empty
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_concat_without_coalescing
|
@@ -120,8 +120,19 @@ module TestAppenders
|
|
120
120
|
@appender.append event
|
121
121
|
end
|
122
122
|
|
123
|
+
private
|
124
|
+
|
125
|
+
def ensure_queue_is_empty
|
126
|
+
start = Time.now
|
127
|
+
|
128
|
+
queue = @appender.instance_variable_get :@c_queue
|
129
|
+
sleep 0.2 until queue.empty? or (Time.now - start > 10)
|
130
|
+
|
131
|
+
thread = @appender.instance_variable_get :@c_thread
|
132
|
+
sleep 0.2 until thread.status == 'sleep' or (Time.now - start > 10)
|
133
|
+
end
|
134
|
+
|
123
135
|
end # class TestGrowl
|
124
136
|
end # module TestLogging
|
125
137
|
end # module TestAppenders
|
126
138
|
|
127
|
-
# EOF
|
data/test/appenders/test_io.rb
CHANGED
@@ -44,8 +44,9 @@ module TestAppenders
|
|
44
44
|
|
45
45
|
def test_periodic_flusher_running
|
46
46
|
flusher = @appender.instance_variable_get(:@periodic_flusher)
|
47
|
-
|
48
47
|
assert_instance_of Logging::Appenders::Buffering::PeriodicFlusher, flusher
|
48
|
+
|
49
|
+
sleep 0.250 # give the flusher thread another moment to start
|
49
50
|
assert flusher.waiting?, 'the periodic flusher should be waiting for a signal'
|
50
51
|
end
|
51
52
|
|