logging 0.4.0 → 0.5.0
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 +32 -0
- data/Manifest.txt +46 -0
- data/README.txt +85 -11
- data/Rakefile +29 -0
- data/{examples → data}/logging.yaml +0 -0
- data/lib/logging.rb +24 -6
- data/lib/logging/appender.rb +2 -12
- data/lib/logging/appenders/console.rb +3 -7
- data/lib/logging/appenders/file.rb +2 -4
- data/lib/logging/appenders/growl.rb +206 -0
- data/lib/logging/appenders/io.rb +2 -6
- data/lib/logging/appenders/rolling_file.rb +3 -7
- data/lib/logging/appenders/static_appender.rb +1 -5
- data/lib/logging/appenders/syslog.rb +210 -0
- data/lib/logging/config/yaml_configurator.rb +2 -10
- data/lib/logging/layout.rb +2 -7
- data/lib/logging/layouts/basic.rb +1 -3
- data/lib/logging/layouts/pattern.rb +1 -9
- data/lib/logging/log_event.rb +2 -4
- data/lib/logging/logger.rb +4 -19
- data/lib/logging/repository.rb +1 -10
- data/lib/logging/root_logger.rb +1 -5
- data/tasks/doc.rake +43 -0
- data/tasks/gem.rake +85 -0
- data/tasks/manifest.rake +39 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +129 -0
- data/tasks/test.rake +35 -0
- data/tasks/website.rake +38 -0
- data/test/appenders/test_syslog.rb +192 -0
- data/test/benchmark.rb +13 -4
- data/test/config/test_yaml_configurator.rb +2 -2
- data/test/setup.rb +23 -21
- data/test/test_logging.rb +2 -2
- data/test/test_repository.rb +3 -5
- metadata +49 -14
- data/test/test_all.rb +0 -5
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: yaml_configurator.rb
|
1
|
+
# $Id: yaml_configurator.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'logging'
|
@@ -6,7 +6,6 @@ require 'logging'
|
|
6
6
|
module Logging
|
7
7
|
module Config
|
8
8
|
|
9
|
-
#
|
10
9
|
# The YamlConfigurator class is used to configure the Logging framework
|
11
10
|
# using information found in a YAML file.
|
12
11
|
#
|
@@ -15,7 +14,7 @@ module Config
|
|
15
14
|
class Error < StandardError; end # :nodoc:
|
16
15
|
|
17
16
|
class << self
|
18
|
-
|
17
|
+
|
19
18
|
# call-seq:
|
20
19
|
# YamlConfigurator.load( file )
|
21
20
|
#
|
@@ -38,7 +37,6 @@ module Config
|
|
38
37
|
end
|
39
38
|
end # class << self
|
40
39
|
|
41
|
-
#
|
42
40
|
# call-seq:
|
43
41
|
# YamlConfigurator.new( io )
|
44
42
|
#
|
@@ -57,7 +55,6 @@ module Config
|
|
57
55
|
end
|
58
56
|
private :initialize
|
59
57
|
|
60
|
-
#
|
61
58
|
# call-seq:
|
62
59
|
# load
|
63
60
|
#
|
@@ -70,7 +67,6 @@ module Config
|
|
70
67
|
loggers @config['loggers']
|
71
68
|
end
|
72
69
|
|
73
|
-
#
|
74
70
|
# call-seq:
|
75
71
|
# pre_config( config )
|
76
72
|
#
|
@@ -97,7 +93,6 @@ module Config
|
|
97
93
|
end
|
98
94
|
end
|
99
95
|
|
100
|
-
#
|
101
96
|
# call-seq:
|
102
97
|
# appenders( ary )
|
103
98
|
#
|
@@ -110,7 +105,6 @@ module Config
|
|
110
105
|
ary.each {|h| appender(h)}
|
111
106
|
end
|
112
107
|
|
113
|
-
#
|
114
108
|
# call-seq:
|
115
109
|
# loggers( ary )
|
116
110
|
#
|
@@ -135,7 +129,6 @@ module Config
|
|
135
129
|
end
|
136
130
|
end
|
137
131
|
|
138
|
-
#
|
139
132
|
# call-seq:
|
140
133
|
# appender( config )
|
141
134
|
#
|
@@ -163,7 +156,6 @@ module Config
|
|
163
156
|
clazz.new(name, config)
|
164
157
|
end
|
165
158
|
|
166
|
-
#
|
167
159
|
# call-seq:
|
168
160
|
# layout( config )
|
169
161
|
#
|
data/lib/logging/layout.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# $Id: layout.rb
|
1
|
+
# $Id: layout.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'logging'
|
5
5
|
|
6
6
|
module Logging
|
7
7
|
|
8
|
-
#
|
9
8
|
# The +Layout+ class provides methods for formatting log events into a
|
10
9
|
# string representation. Layouts are used by Appenders to format log
|
11
10
|
# events before writing them to the logging destination.
|
@@ -16,7 +15,6 @@ module Logging
|
|
16
15
|
#
|
17
16
|
class Layout
|
18
17
|
|
19
|
-
#
|
20
18
|
# call-seq:
|
21
19
|
# Layout.new( :format_as => :string )
|
22
20
|
#
|
@@ -43,7 +41,6 @@ module Logging
|
|
43
41
|
else :string end
|
44
42
|
end
|
45
43
|
|
46
|
-
#
|
47
44
|
# call-seq:
|
48
45
|
# format( event )
|
49
46
|
#
|
@@ -52,7 +49,6 @@ module Logging
|
|
52
49
|
#
|
53
50
|
def format( event ) nil end
|
54
51
|
|
55
|
-
#
|
56
52
|
# call-seq:
|
57
53
|
# header
|
58
54
|
#
|
@@ -61,7 +57,6 @@ module Logging
|
|
61
57
|
#
|
62
58
|
def header( ) '' end
|
63
59
|
|
64
|
-
#
|
65
60
|
# call-seq:
|
66
61
|
# footer
|
67
62
|
#
|
@@ -71,7 +66,7 @@ module Logging
|
|
71
66
|
|
72
67
|
|
73
68
|
protected
|
74
|
-
|
69
|
+
|
75
70
|
# call-seq:
|
76
71
|
# format_obj( obj )
|
77
72
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: basic.rb
|
1
|
+
# $Id: basic.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'logging'
|
4
4
|
require 'logging/layout'
|
@@ -7,7 +7,6 @@ require 'logging/layout'
|
|
7
7
|
module Logging
|
8
8
|
module Layouts
|
9
9
|
|
10
|
-
#
|
11
10
|
# The +Basic+ layout class provides methods for simple formatting of log
|
12
11
|
# events. The resulting string follows the format below.
|
13
12
|
#
|
@@ -21,7 +20,6 @@ module Layouts
|
|
21
20
|
#
|
22
21
|
class Basic < ::Logging::Layout
|
23
22
|
|
24
|
-
#
|
25
23
|
# call-seq:
|
26
24
|
# format( event )
|
27
25
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: pattern.rb
|
1
|
+
# $Id: pattern.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'logging'
|
4
4
|
require 'logging/layout'
|
@@ -6,7 +6,6 @@ require 'logging/layout'
|
|
6
6
|
module Logging
|
7
7
|
module Layouts
|
8
8
|
|
9
|
-
#
|
10
9
|
# A flexible layout configurable with pattern string.
|
11
10
|
#
|
12
11
|
# The goal of this class is to format a LogEvent and return the results as
|
@@ -144,7 +143,6 @@ module Layouts
|
|
144
143
|
# default date format
|
145
144
|
ISO8601 = "%Y-%m-%d %H:%M:%S"
|
146
145
|
|
147
|
-
#
|
148
146
|
# call-seq:
|
149
147
|
# Pattern.create_date_format_methods( pf )
|
150
148
|
#
|
@@ -173,7 +171,6 @@ module Layouts
|
|
173
171
|
pf.meta_eval code
|
174
172
|
end
|
175
173
|
|
176
|
-
#
|
177
174
|
# call-seq:
|
178
175
|
# Pattern.create_format_method( pf )
|
179
176
|
#
|
@@ -215,7 +212,6 @@ module Layouts
|
|
215
212
|
end
|
216
213
|
# :startdoc:
|
217
214
|
|
218
|
-
#
|
219
215
|
# call-seq:
|
220
216
|
# Pattern.new( opts )
|
221
217
|
#
|
@@ -244,7 +240,6 @@ module Layouts
|
|
244
240
|
|
245
241
|
attr_reader :pattern, :date_pattern, :date_method
|
246
242
|
|
247
|
-
#
|
248
243
|
# call-seq:
|
249
244
|
# appender.pattern = "[%d] %-5l -- %c : %m\n"
|
250
245
|
#
|
@@ -255,7 +250,6 @@ module Layouts
|
|
255
250
|
Pattern.create_format_method(self)
|
256
251
|
end
|
257
252
|
|
258
|
-
#
|
259
253
|
# call-seq:
|
260
254
|
# appender.date_pattern = "%Y-%m-%d %H:%M:%S"
|
261
255
|
#
|
@@ -267,7 +261,6 @@ module Layouts
|
|
267
261
|
Pattern.create_date_format_methods(self)
|
268
262
|
end
|
269
263
|
|
270
|
-
#
|
271
264
|
# call-seq:
|
272
265
|
# appender.date_method = 'to_s'
|
273
266
|
# appender.date_method = :usec
|
@@ -283,7 +276,6 @@ module Layouts
|
|
283
276
|
|
284
277
|
# :stopdoc:
|
285
278
|
|
286
|
-
#
|
287
279
|
# call-seq:
|
288
280
|
# meta_eval( code )
|
289
281
|
#
|
data/lib/logging/log_event.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# $Id: log_event.rb
|
1
|
+
# $Id: log_event.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
module Logging
|
4
4
|
|
5
|
-
#
|
6
5
|
# This class defines a logging event.
|
7
6
|
#
|
8
7
|
class LogEvent
|
@@ -17,7 +16,6 @@ module Logging
|
|
17
16
|
CALLER_RGXP = %r/([\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
|
18
17
|
# :startdoc:
|
19
18
|
|
20
|
-
#
|
21
19
|
# call-seq:
|
22
20
|
# LogEvent.new( logger, level, [data], trace )
|
23
21
|
#
|
@@ -49,4 +47,4 @@ module Logging
|
|
49
47
|
end # class LogEvent
|
50
48
|
end # module Logging
|
51
49
|
|
52
|
-
#EOF
|
50
|
+
# EOF
|
data/lib/logging/logger.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: logger.rb
|
1
|
+
# $Id: logger.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'thread'
|
4
4
|
require 'logging'
|
@@ -9,7 +9,6 @@ require 'logging/repository'
|
|
9
9
|
|
10
10
|
module Logging
|
11
11
|
|
12
|
-
#
|
13
12
|
# The +Logger+ class is the primary interface to the +Logging+ framework.
|
14
13
|
# It provides the logging methods that will be called from user methods,
|
15
14
|
# and it generates logging events that are sent to the appenders (the
|
@@ -22,7 +21,7 @@ module Logging
|
|
22
21
|
# Example:
|
23
22
|
#
|
24
23
|
# log = Logging::Logger['my logger']
|
25
|
-
# log.add( Logging::Appenders::
|
24
|
+
# log.add( Logging::Appenders::Stdout.new ) # append to STDOUT
|
26
25
|
# log.level = :info # log 'info' and above
|
27
26
|
#
|
28
27
|
# log.info 'starting foo operation'
|
@@ -36,7 +35,7 @@ module Logging
|
|
36
35
|
@mutex = Mutex.new # :nodoc:
|
37
36
|
|
38
37
|
class << self
|
39
|
-
|
38
|
+
|
40
39
|
# call-seq:
|
41
40
|
# Logger.root
|
42
41
|
#
|
@@ -48,7 +47,6 @@ module Logging
|
|
48
47
|
|
49
48
|
# :stopdoc:
|
50
49
|
|
51
|
-
#
|
52
50
|
# Overrides the new method such that only one Logger will be created
|
53
51
|
# for any given logger name.
|
54
52
|
#
|
@@ -69,7 +67,6 @@ module Logging
|
|
69
67
|
end
|
70
68
|
alias :[] :new
|
71
69
|
|
72
|
-
#
|
73
70
|
# This is where the actual logging methods are defined. Two methods
|
74
71
|
# are created for each log level. The first is a query method used to
|
75
72
|
# determine if that perticular logging level is enabled. The second is
|
@@ -122,7 +119,6 @@ module Logging
|
|
122
119
|
|
123
120
|
attr_reader :level, :name, :parent, :additive, :trace
|
124
121
|
|
125
|
-
#
|
126
122
|
# call-seq:
|
127
123
|
# Logger.new( name )
|
128
124
|
# Logger[name]
|
@@ -162,7 +158,6 @@ module Logging
|
|
162
158
|
repo.children(name).each {|c| c.parent = self}
|
163
159
|
end
|
164
160
|
|
165
|
-
#
|
166
161
|
# call-seq:
|
167
162
|
# log <=> other
|
168
163
|
#
|
@@ -177,7 +172,6 @@ module Logging
|
|
177
172
|
else raise ArgumentError, 'expecting a Logger instance' end
|
178
173
|
end
|
179
174
|
|
180
|
-
#
|
181
175
|
# call-seq:
|
182
176
|
# log << "message"
|
183
177
|
#
|
@@ -190,7 +184,6 @@ module Logging
|
|
190
184
|
@parent << msg if @additive
|
191
185
|
end
|
192
186
|
|
193
|
-
#
|
194
187
|
# call-seq:
|
195
188
|
# additive = true
|
196
189
|
#
|
@@ -206,7 +199,6 @@ module Logging
|
|
206
199
|
else raise ArgumentError, 'expecting a boolean' end
|
207
200
|
end
|
208
201
|
|
209
|
-
#
|
210
202
|
# call-seq:
|
211
203
|
# trace = true
|
212
204
|
#
|
@@ -222,7 +214,6 @@ module Logging
|
|
222
214
|
else raise ArgumentError, 'expecting a boolean' end
|
223
215
|
end
|
224
216
|
|
225
|
-
#
|
226
217
|
# call-seq:
|
227
218
|
# level = :all
|
228
219
|
#
|
@@ -269,7 +260,6 @@ module Logging
|
|
269
260
|
@level
|
270
261
|
end
|
271
262
|
|
272
|
-
#
|
273
263
|
# call-seq:
|
274
264
|
# appenders = app
|
275
265
|
#
|
@@ -281,7 +271,6 @@ module Logging
|
|
281
271
|
add(*args) unless args.nil?
|
282
272
|
end
|
283
273
|
|
284
|
-
#
|
285
274
|
# call-seq:
|
286
275
|
# add( appenders )
|
287
276
|
#
|
@@ -298,7 +287,6 @@ module Logging
|
|
298
287
|
end
|
299
288
|
end
|
300
289
|
|
301
|
-
#
|
302
290
|
# call-seq:
|
303
291
|
# remove( appenders )
|
304
292
|
#
|
@@ -320,7 +308,6 @@ module Logging
|
|
320
308
|
end
|
321
309
|
end
|
322
310
|
|
323
|
-
#
|
324
311
|
# call-seq:
|
325
312
|
# clear
|
326
313
|
#
|
@@ -330,7 +317,7 @@ module Logging
|
|
330
317
|
|
331
318
|
|
332
319
|
protected
|
333
|
-
|
320
|
+
|
334
321
|
# call-seq:
|
335
322
|
# parent = ParentLogger
|
336
323
|
#
|
@@ -340,7 +327,6 @@ module Logging
|
|
340
327
|
#
|
341
328
|
def parent=( parent ) @parent = parent end
|
342
329
|
|
343
|
-
#
|
344
330
|
# call-seq:
|
345
331
|
# log_event( event )
|
346
332
|
#
|
@@ -355,7 +341,6 @@ module Logging
|
|
355
341
|
|
356
342
|
# :stopdoc:
|
357
343
|
|
358
|
-
#
|
359
344
|
# call-seq:
|
360
345
|
# meta_eval( code )
|
361
346
|
#
|
data/lib/logging/repository.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: repository.rb
|
1
|
+
# $Id: repository.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'singleton'
|
4
4
|
require 'logging/root_logger'
|
@@ -6,7 +6,6 @@ require 'logging/root_logger'
|
|
6
6
|
|
7
7
|
module Logging
|
8
8
|
|
9
|
-
#
|
10
9
|
# The Repository is a hash that stores references to all Loggers
|
11
10
|
# that have been created. It provides methods to determine parent/child
|
12
11
|
# relationships between Loggers and to retrieve Loggers from the hash.
|
@@ -16,7 +15,6 @@ module Logging
|
|
16
15
|
|
17
16
|
PATH_DELIMITER = '::' # :nodoc:
|
18
17
|
|
19
|
-
#
|
20
18
|
# nodoc:
|
21
19
|
#
|
22
20
|
# This is a singleton class -- use the +instance+ method to obtain the
|
@@ -26,7 +24,6 @@ module Logging
|
|
26
24
|
@h = {:root => ::Logging::RootLogger.new}
|
27
25
|
end
|
28
26
|
|
29
|
-
#
|
30
27
|
# call-seq:
|
31
28
|
# instance[name]
|
32
29
|
#
|
@@ -51,7 +48,6 @@ module Logging
|
|
51
48
|
#
|
52
49
|
def []( key ) @h[to_key(key)] end
|
53
50
|
|
54
|
-
#
|
55
51
|
# call-seq:
|
56
52
|
# instance[name] = logger
|
57
53
|
#
|
@@ -64,7 +60,6 @@ module Logging
|
|
64
60
|
#
|
65
61
|
def []=( key, val ) @h[to_key(key)] = val end
|
66
62
|
|
67
|
-
#
|
68
63
|
# call-seq:
|
69
64
|
# fetch( name )
|
70
65
|
#
|
@@ -78,7 +73,6 @@ module Logging
|
|
78
73
|
#
|
79
74
|
def fetch( key ) @h.fetch(to_key(key)) end
|
80
75
|
|
81
|
-
#
|
82
76
|
# call-seq:
|
83
77
|
# has_logger?( name )
|
84
78
|
#
|
@@ -92,7 +86,6 @@ module Logging
|
|
92
86
|
#
|
93
87
|
def has_logger?( key ) @h.has_key?(to_key(key)) end
|
94
88
|
|
95
|
-
#
|
96
89
|
# call-seq:
|
97
90
|
# parent( key )
|
98
91
|
#
|
@@ -113,7 +106,6 @@ module Logging
|
|
113
106
|
p
|
114
107
|
end
|
115
108
|
|
116
|
-
#
|
117
109
|
# call-seq:
|
118
110
|
# children( key )
|
119
111
|
#
|
@@ -137,7 +129,6 @@ module Logging
|
|
137
129
|
a.compact.sort
|
138
130
|
end
|
139
131
|
|
140
|
-
#
|
141
132
|
# call-seq:
|
142
133
|
# to_key( key )
|
143
134
|
#
|