logging 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/History.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
== 0.5.0 / 2007-11-18
|
2
|
+
|
3
|
+
* Added the ability to log via the syslog daemon
|
4
|
+
* Can send messages to the Growl notification system on Mac OS X
|
5
|
+
* The Growl appender can coalesce messages of the same title/priority
|
6
|
+
|
7
|
+
== 0.4.0 / 2007-03-21
|
8
|
+
|
9
|
+
* Added a microsecond flag to the Pattern layout
|
10
|
+
* All appenders write immediately upon receipt of a logging event
|
11
|
+
* Added a basic logging method tha returns a logger object configured in the
|
12
|
+
same manner as the standard Ruby logger
|
13
|
+
* Fixed a bug caused by nil log messages
|
14
|
+
|
15
|
+
== 0.3.1 / 2007-02-08
|
16
|
+
|
17
|
+
* Bugfix Release
|
18
|
+
|
19
|
+
== 0.3.0 / 2007-02-01
|
20
|
+
|
21
|
+
* Remove the ability to log multiple objects from a single log method call
|
22
|
+
|
23
|
+
== 0.2.0 / 2007-01-29
|
24
|
+
|
25
|
+
* The "once every four years" release
|
26
|
+
* Storage and retrieveal of appenders by name
|
27
|
+
* YAML configuration support
|
28
|
+
* Rolling file appender
|
29
|
+
|
30
|
+
== 0.1.0 / 2007-01-12
|
31
|
+
|
32
|
+
* Birthday!
|
data/Manifest.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
data/logging.yaml
|
6
|
+
lib/logging.rb
|
7
|
+
lib/logging/appender.rb
|
8
|
+
lib/logging/appenders/console.rb
|
9
|
+
lib/logging/appenders/file.rb
|
10
|
+
lib/logging/appenders/growl.rb
|
11
|
+
lib/logging/appenders/io.rb
|
12
|
+
lib/logging/appenders/rolling_file.rb
|
13
|
+
lib/logging/appenders/static_appender.rb
|
14
|
+
lib/logging/appenders/syslog.rb
|
15
|
+
lib/logging/config/yaml_configurator.rb
|
16
|
+
lib/logging/layout.rb
|
17
|
+
lib/logging/layouts/basic.rb
|
18
|
+
lib/logging/layouts/pattern.rb
|
19
|
+
lib/logging/log_event.rb
|
20
|
+
lib/logging/logger.rb
|
21
|
+
lib/logging/repository.rb
|
22
|
+
lib/logging/root_logger.rb
|
23
|
+
tasks/doc.rake
|
24
|
+
tasks/gem.rake
|
25
|
+
tasks/manifest.rake
|
26
|
+
tasks/rubyforge.rake
|
27
|
+
tasks/setup.rb
|
28
|
+
tasks/test.rake
|
29
|
+
tasks/website.rake
|
30
|
+
test/appenders/test_console.rb
|
31
|
+
test/appenders/test_file.rb
|
32
|
+
test/appenders/test_io.rb
|
33
|
+
test/appenders/test_rolling_file.rb
|
34
|
+
test/appenders/test_syslog.rb
|
35
|
+
test/benchmark.rb
|
36
|
+
test/config/test_yaml_configurator.rb
|
37
|
+
test/layouts/test_basic.rb
|
38
|
+
test/layouts/test_pattern.rb
|
39
|
+
test/setup.rb
|
40
|
+
test/test_appender.rb
|
41
|
+
test/test_layout.rb
|
42
|
+
test/test_log_event.rb
|
43
|
+
test/test_logger.rb
|
44
|
+
test/test_logging.rb
|
45
|
+
test/test_repository.rb
|
46
|
+
test/test_root_logger.rb
|
data/README.txt
CHANGED
@@ -1,15 +1,89 @@
|
|
1
|
-
|
2
|
-
$Id: README.txt 35 2007-03-21 19:32:32Z tim_pease $
|
3
|
-
++
|
1
|
+
Logging
|
4
2
|
|
5
|
-
|
3
|
+
* {Homepage}[http://logging.rubyforge.org/]
|
4
|
+
* {Rubyforge Project}[http://rubyforge.org/projects/logging]
|
5
|
+
* email tim dot pease at gmail dot com
|
6
6
|
|
7
|
-
|
7
|
+
== DESCRIPTION:
|
8
8
|
|
9
|
-
|
9
|
+
Logging is a flexible logging library for use in Ruby programs based on the
|
10
|
+
design of Java's log4j library. It features a hierarchical logging system,
|
11
|
+
custom level names, multiple output destinations per log event, custom
|
12
|
+
formatting, and more.
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
== INSTALL:
|
15
|
+
|
16
|
+
sudo gem install logging
|
17
|
+
|
18
|
+
== EXAMPLE:
|
19
|
+
|
20
|
+
This example configures a logger to output messages in a format similar to the
|
21
|
+
core ruby Logger class. Only log messages that are warnings or higher will be
|
22
|
+
logged.
|
23
|
+
|
24
|
+
require 'logging'
|
25
|
+
|
26
|
+
logger = Logging.logger(STDOUT)
|
27
|
+
logger.level = :warn
|
28
|
+
|
29
|
+
logger.debug "this debug message will not be output by the logger"
|
30
|
+
logger.warn "this is your last warning"
|
31
|
+
|
32
|
+
In this example, a single logger is crated that will append to STDOUT and to a file. Only log messages that are informational or higher will be logged.
|
33
|
+
|
34
|
+
reqruie 'logging'
|
35
|
+
|
36
|
+
logger = Logging::Logger['example_logger']
|
37
|
+
logger.add Logging::Appender.stdout
|
38
|
+
logger.add Logging::Appenders::File.new('example.log')
|
39
|
+
logger.level = :info
|
40
|
+
|
41
|
+
logger.debug "this debug message will not be output by the logger"
|
42
|
+
logger.info "just some friendly advice"
|
43
|
+
|
44
|
+
The Logging library was created to allow each class in a program to have its
|
45
|
+
own configurable logger. The logging level for a particular class can be
|
46
|
+
changed independently of all other loggers in the system. This example shows
|
47
|
+
the recommended way of accomplishing this.
|
48
|
+
|
49
|
+
require 'logging'
|
50
|
+
|
51
|
+
Logging::Logger['FirstClass'].level = :warn
|
52
|
+
Logging::Logger['SecondClass'].level = :debug
|
53
|
+
|
54
|
+
class FirstClass
|
55
|
+
def initialize
|
56
|
+
@log = Logging::Logger[self]
|
57
|
+
end
|
58
|
+
|
59
|
+
def some_method
|
60
|
+
@log.debug = "some method was called on #{self.inspect}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class SecondClass
|
65
|
+
def initialize
|
66
|
+
@log = Logging::Logger[self]
|
67
|
+
end
|
68
|
+
|
69
|
+
def another_method
|
70
|
+
@log.debug = "another method was called on #{self.inspect}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
== NOTES:
|
75
|
+
|
76
|
+
Although Logging is intended to supersede Log4r, it is not a one-to-one
|
77
|
+
replacement for the Log4r library. Most notably is the difference in namespaces
|
78
|
+
-- Logging vs. Log4r. Other differences include renaming Log4r::Outputter to
|
79
|
+
Logging::Appender and renaming Log4r::Formatter to Logging::Layout. These
|
80
|
+
changes were meant to bring the Logging class names more in line with the Log4j
|
81
|
+
class names.
|
82
|
+
|
83
|
+
== REQUIREMENTS:
|
84
|
+
|
85
|
+
Logging does not depend on any other installed libraries or gems.
|
86
|
+
|
87
|
+
== LICENSE:
|
88
|
+
|
89
|
+
Ruby
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
load './tasks/setup.rb'
|
4
|
+
ensure_in_path 'lib'
|
5
|
+
|
6
|
+
require 'logging'
|
7
|
+
|
8
|
+
task :default => 'test:run'
|
9
|
+
|
10
|
+
PROJ.name = 'logging'
|
11
|
+
PROJ.summary = 'A flexible and extendable logging library for Ruby'
|
12
|
+
PROJ.authors = 'Tim Pease'
|
13
|
+
PROJ.email = 'tim.pease@gmail.com'
|
14
|
+
PROJ.url = 'http://logging.rubyforge.org/'
|
15
|
+
PROJ.description = paragraphs_of('README.txt', 3).join("\n\n")
|
16
|
+
PROJ.changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
PROJ.rubyforge_name = 'logging'
|
18
|
+
PROJ.rdoc_dir = 'doc/rdoc'
|
19
|
+
#PROJ.rdoc_remote_dir = 'rdoc'
|
20
|
+
PROJ.rdoc_remote_dir = ''
|
21
|
+
PROJ.version = Logging::VERSION
|
22
|
+
|
23
|
+
PROJ.exclude << '^(\.\/|\/)?website/output'
|
24
|
+
PROJ.exclude << '^(\.\/|\/)?doc'
|
25
|
+
PROJ.exclude << '^(\.\/|\/)?tags$'
|
26
|
+
PROJ.rdoc_exclude << '^(\.\/|\/)?data'
|
27
|
+
PROJ.rdoc_exclude << '^(\.\/|\/)?website'
|
28
|
+
|
29
|
+
# EOF
|
File without changes
|
data/lib/logging.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
# $Id: logging.rb
|
1
|
+
# $Id: logging.rb 47 2007-11-13 05:14:55Z tim_pease $
|
2
2
|
|
3
3
|
require 'logging/repository'
|
4
4
|
|
5
5
|
# require all appenders
|
6
6
|
require 'logging/appenders/console'
|
7
7
|
require 'logging/appenders/file'
|
8
|
+
require 'logging/appenders/growl'
|
8
9
|
require 'logging/appenders/rolling_file'
|
9
10
|
require 'logging/appenders/static_appender'
|
11
|
+
require 'logging/appenders/syslog'
|
10
12
|
|
11
13
|
# require all layouts
|
12
14
|
require 'logging/layouts/basic'
|
@@ -16,16 +18,17 @@ require 'logging/layouts/pattern'
|
|
16
18
|
require 'logging/config/yaml_configurator'
|
17
19
|
|
18
20
|
|
19
|
-
#
|
20
21
|
#
|
21
22
|
#
|
22
23
|
module Logging
|
23
24
|
|
25
|
+
VERSION = '0.5.0' # :nodoc:
|
26
|
+
|
24
27
|
LEVELS = {} # :nodoc:
|
25
28
|
LNAMES = {} # :nodoc:
|
26
29
|
|
27
30
|
class << self
|
28
|
-
|
31
|
+
|
29
32
|
# call-seq:
|
30
33
|
# Logging.configure( filename )
|
31
34
|
#
|
@@ -40,7 +43,6 @@ module Logging
|
|
40
43
|
else raise ArgumentError, 'unknown configuration file format' end
|
41
44
|
end
|
42
45
|
|
43
|
-
#
|
44
46
|
# call-seq:
|
45
47
|
# Logging.logger( device, age = 7, size = 1048576 )
|
46
48
|
# Logging.logger( device, age = 'weekly' )
|
@@ -137,7 +139,6 @@ module Logging
|
|
137
139
|
logger
|
138
140
|
end
|
139
141
|
|
140
|
-
#
|
141
142
|
# call-seq:
|
142
143
|
# Logging.define_levels( levels )
|
143
144
|
#
|
@@ -198,7 +199,6 @@ module Logging
|
|
198
199
|
levels.keys
|
199
200
|
end
|
200
201
|
|
201
|
-
#
|
202
202
|
# call-seq:
|
203
203
|
# Logging.format_as( obj_format )
|
204
204
|
#
|
@@ -225,6 +225,8 @@ module Logging
|
|
225
225
|
end
|
226
226
|
|
227
227
|
# :stopdoc:
|
228
|
+
|
229
|
+
# Convert the given level into a connaconical form - a lowercase string.
|
228
230
|
def levelify( level )
|
229
231
|
case level
|
230
232
|
when String: level.downcase
|
@@ -232,6 +234,7 @@ module Logging
|
|
232
234
|
else raise ArgumentError, "levels must be a String or Symbol" end
|
233
235
|
end
|
234
236
|
|
237
|
+
# Convert the given level into a level number.
|
235
238
|
def level_num( level )
|
236
239
|
l = levelify level
|
237
240
|
case l
|
@@ -239,6 +242,21 @@ module Logging
|
|
239
242
|
when 'off': LEVELS.length
|
240
243
|
else begin; Integer(l); rescue ArgumentError; LEVELS[l] end end
|
241
244
|
end
|
245
|
+
|
246
|
+
# Helper method for retrieving options from a hash.
|
247
|
+
def options( opts = {} )
|
248
|
+
lambda do |*args|
|
249
|
+
keys, default, ignored = args
|
250
|
+
catch('opt') do
|
251
|
+
Array(keys).each do |key|
|
252
|
+
[key, key.to_s, key.to_s.intern].each do |key|
|
253
|
+
throw 'opt', opts[key] if opts.has_key?(key)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
default
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
242
260
|
# :startdoc:
|
243
261
|
end
|
244
262
|
|
data/lib/logging/appender.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: appender.rb
|
1
|
+
# $Id: appender.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'thread'
|
4
4
|
require 'logging'
|
@@ -8,7 +8,6 @@ require 'logging/layouts/basic'
|
|
8
8
|
|
9
9
|
module Logging
|
10
10
|
|
11
|
-
#
|
12
11
|
# The +Appender+ class is provides methods for appending log events to a
|
13
12
|
# logging destination. The log events are formatted into strings using a
|
14
13
|
# Layout.
|
@@ -26,7 +25,6 @@ module Logging
|
|
26
25
|
|
27
26
|
attr_reader :name, :layout, :level
|
28
27
|
|
29
|
-
#
|
30
28
|
# call-seq:
|
31
29
|
# Appender.new( name )
|
32
30
|
# Appender.new( name, :layout => layout )
|
@@ -52,7 +50,6 @@ module Logging
|
|
52
50
|
::Logging::Appender[@name] = self
|
53
51
|
end
|
54
52
|
|
55
|
-
#
|
56
53
|
# call-seq:
|
57
54
|
# append( event )
|
58
55
|
#
|
@@ -69,7 +66,6 @@ module Logging
|
|
69
66
|
self
|
70
67
|
end
|
71
68
|
|
72
|
-
#
|
73
69
|
# call-seq:
|
74
70
|
# appender << string
|
75
71
|
#
|
@@ -86,7 +82,6 @@ module Logging
|
|
86
82
|
self
|
87
83
|
end
|
88
84
|
|
89
|
-
#
|
90
85
|
# call-seq:
|
91
86
|
# level = :all
|
92
87
|
#
|
@@ -129,7 +124,6 @@ module Logging
|
|
129
124
|
@level = lvl
|
130
125
|
end
|
131
126
|
|
132
|
-
#
|
133
127
|
# call-seq
|
134
128
|
# appender.layout = Logging::Layouts::Basic.new
|
135
129
|
#
|
@@ -143,7 +137,6 @@ module Logging
|
|
143
137
|
@layout = layout
|
144
138
|
end
|
145
139
|
|
146
|
-
#
|
147
140
|
# call-seq:
|
148
141
|
# close( footer = true )
|
149
142
|
#
|
@@ -159,7 +152,6 @@ module Logging
|
|
159
152
|
self
|
160
153
|
end
|
161
154
|
|
162
|
-
#
|
163
155
|
# call-seq:
|
164
156
|
# closed?
|
165
157
|
#
|
@@ -169,7 +161,6 @@ module Logging
|
|
169
161
|
#
|
170
162
|
def closed?( ) @closed end
|
171
163
|
|
172
|
-
#
|
173
164
|
# call-seq:
|
174
165
|
# flush
|
175
166
|
#
|
@@ -180,7 +171,7 @@ module Logging
|
|
180
171
|
|
181
172
|
|
182
173
|
private
|
183
|
-
|
174
|
+
|
184
175
|
# call-seq:
|
185
176
|
# write( str )
|
186
177
|
#
|
@@ -189,7 +180,6 @@ module Logging
|
|
189
180
|
#
|
190
181
|
def write( str ) nil end
|
191
182
|
|
192
|
-
#
|
193
183
|
# call-seq:
|
194
184
|
# sync { block }
|
195
185
|
#
|
@@ -1,16 +1,14 @@
|
|
1
|
-
# $Id: console.rb
|
1
|
+
# $Id: console.rb 37 2007-10-26 19:12:44Z tim_pease $
|
2
2
|
|
3
3
|
require 'logging/appenders/io'
|
4
4
|
|
5
5
|
module Logging
|
6
6
|
module Appenders
|
7
7
|
|
8
|
-
#
|
9
8
|
# This class provides an Appender that can write to STDOUT.
|
10
9
|
#
|
11
|
-
class Stdout< ::Logging::Appenders::IO
|
10
|
+
class Stdout < ::Logging::Appenders::IO
|
12
11
|
|
13
|
-
#
|
14
12
|
# call-seq:
|
15
13
|
# Stdout.new
|
16
14
|
# Stdout.new( :layout => layout )
|
@@ -24,12 +22,10 @@ module Appenders
|
|
24
22
|
end
|
25
23
|
end # class Stdout
|
26
24
|
|
27
|
-
#
|
28
25
|
# This class provides an Appender that can write to STDERR.
|
29
26
|
#
|
30
|
-
class Stderr< ::Logging::Appenders::IO
|
27
|
+
class Stderr < ::Logging::Appenders::IO
|
31
28
|
|
32
|
-
#
|
33
29
|
# call-seq:
|
34
30
|
# Stderr.new
|
35
31
|
# Stderr.new( :layout => layout )
|
@@ -1,15 +1,13 @@
|
|
1
|
-
# $Id: file.rb
|
1
|
+
# $Id: file.rb 46 2007-10-31 14:39:01Z tim_pease $
|
2
2
|
|
3
3
|
require 'logging/appenders/io'
|
4
4
|
|
5
5
|
module Logging::Appenders
|
6
6
|
|
7
|
-
#
|
8
7
|
# This class provides an Appender that can write to a File.
|
9
8
|
#
|
10
9
|
class File < ::Logging::Appenders::IO
|
11
10
|
|
12
|
-
#
|
13
11
|
# call-seq:
|
14
12
|
# File.new( name, :filename => 'file' )
|
15
13
|
# File.new( name, :filename => 'file', :truncate => true )
|
@@ -22,7 +20,7 @@ module Logging::Appenders
|
|
22
20
|
# appened to the file.
|
23
21
|
#
|
24
22
|
def initialize( name, opts = {} )
|
25
|
-
@fn = opts.delete(:filename) || opts.delete('filename')
|
23
|
+
@fn = opts.delete(:filename) || opts.delete('filename') || name
|
26
24
|
raise ArgumentError, 'no filename was given' if @fn.nil?
|
27
25
|
|
28
26
|
mode = opts.delete(:truncate) || opts.delete('truncate')
|