filterfish-logging 0.9.8

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.
Files changed (55) hide show
  1. data/History.txt +176 -0
  2. data/Manifest.txt +54 -0
  3. data/README.txt +93 -0
  4. data/Rakefile +28 -0
  5. data/data/logging.yaml +63 -0
  6. data/lib/logging.rb +288 -0
  7. data/lib/logging/appender.rb +257 -0
  8. data/lib/logging/appenders/console.rb +43 -0
  9. data/lib/logging/appenders/email.rb +131 -0
  10. data/lib/logging/appenders/file.rb +55 -0
  11. data/lib/logging/appenders/growl.rb +182 -0
  12. data/lib/logging/appenders/io.rb +81 -0
  13. data/lib/logging/appenders/rolling_file.rb +293 -0
  14. data/lib/logging/appenders/syslog.rb +202 -0
  15. data/lib/logging/config/yaml_configurator.rb +197 -0
  16. data/lib/logging/layout.rb +103 -0
  17. data/lib/logging/layouts/basic.rb +35 -0
  18. data/lib/logging/layouts/pattern.rb +292 -0
  19. data/lib/logging/log_event.rb +50 -0
  20. data/lib/logging/logger.rb +388 -0
  21. data/lib/logging/repository.rb +151 -0
  22. data/lib/logging/root_logger.rb +60 -0
  23. data/lib/logging/utils.rb +44 -0
  24. data/tasks/ann.rake +78 -0
  25. data/tasks/bones.rake +21 -0
  26. data/tasks/gem.rake +106 -0
  27. data/tasks/manifest.rake +49 -0
  28. data/tasks/notes.rake +22 -0
  29. data/tasks/post_load.rake +37 -0
  30. data/tasks/rdoc.rake +49 -0
  31. data/tasks/rubyforge.rake +57 -0
  32. data/tasks/setup.rb +253 -0
  33. data/tasks/svn.rake +45 -0
  34. data/tasks/test.rake +38 -0
  35. data/test/appenders/test_console.rb +40 -0
  36. data/test/appenders/test_email.rb +167 -0
  37. data/test/appenders/test_file.rb +94 -0
  38. data/test/appenders/test_growl.rb +115 -0
  39. data/test/appenders/test_io.rb +113 -0
  40. data/test/appenders/test_rolling_file.rb +187 -0
  41. data/test/appenders/test_syslog.rb +192 -0
  42. data/test/benchmark.rb +88 -0
  43. data/test/config/test_yaml_configurator.rb +41 -0
  44. data/test/layouts/test_basic.rb +44 -0
  45. data/test/layouts/test_pattern.rb +173 -0
  46. data/test/setup.rb +66 -0
  47. data/test/test_appender.rb +162 -0
  48. data/test/test_layout.rb +85 -0
  49. data/test/test_log_event.rb +81 -0
  50. data/test/test_logger.rb +589 -0
  51. data/test/test_logging.rb +250 -0
  52. data/test/test_repository.rb +123 -0
  53. data/test/test_root_logger.rb +82 -0
  54. data/test/test_utils.rb +48 -0
  55. metadata +126 -0
data/History.txt ADDED
@@ -0,0 +1,176 @@
1
+ == 0.9.8 / 2009-04-04 [rgh@roughage.com.au]
2
+
3
+ 1 Minor enhancement
4
+ - Allow the config to passed as a string.
5
+
6
+ == 0.9.7 / 2009-03-17
7
+
8
+ 1 minor enhancement
9
+ - Added a StringIO appender
10
+ 1 bug fix
11
+ - Handling objects that cannot be dumped via YAML [Tim Galeckas]
12
+
13
+ == 0.9.6 / 2009-02-02
14
+
15
+ 2 minor enhancements
16
+ - Ruby 1.9.1 compatability
17
+ - JRuby 1.1.5 compatability
18
+
19
+ == 0.9.5 / 2009-01-25
20
+
21
+ 2 minor enhancements
22
+ - The pattern layout can output the current thread name
23
+ if set using Thread.current[:name] [valodzka]
24
+ - Added buffered logging to all IO based loggers
25
+ (console, file, rolling file)
26
+ 1 bug fix
27
+ - Uncaught TimeoutError in the e-mail appender
28
+
29
+ == 0.9.4 / 2008-10-04
30
+
31
+ 2 minor enhancements
32
+ - Flag to suppress exception backtraces from being logged
33
+ - Cleaning up color codes on Growl output
34
+ 4 bug fixes
35
+ - Child loggers were not being found in some cases
36
+ - RollingFileAppender fails to reopen the log file if
37
+ the log file is deleted.
38
+ - Fixed a copy/paste error in the YAML configurator
39
+ - Bug in the configurator where a nil object was being used
40
+
41
+ == 0.9.3 / 2008-09-12
42
+
43
+ 2 minor enhancement
44
+ - Added a class for tracking basic statistics
45
+ - Will use the 'fastthread' gem if availble
46
+
47
+ == 0.9.2 / 2008-09-03
48
+
49
+ 2 bug fixes
50
+ - Properly generates logger names for anonymous classes and
51
+ modules and meta-classes
52
+ - Fixed the rescue clause when 'turn' cannot be required
53
+
54
+ == 0.9.1 / 2008-08-14
55
+
56
+ 1 minor enhancement
57
+ - added a method to show the logging configuration
58
+ 2 bug fixes
59
+ - checking for sync method on the IO streams before calling
60
+ - fixed the internal logging levels
61
+
62
+ == 0.9.0 / 2008-07-16
63
+
64
+ 2 minor enhancement
65
+ - Exceptions from appenders are captured and logged
66
+ - Internal logger for the Logging framework (disabled by default)
67
+ - Added a DSL configuration format (more readable than YAML)
68
+ 1 bug fix
69
+ - Modules could not have their own logger instance
70
+
71
+ == 0.8.0 / 2008-07-02
72
+
73
+ 1 minor enhancement
74
+ - Setting the log level of a parent will cause this level to
75
+ be propagated to the children
76
+ 1 bug fix
77
+ - Fixed error with the e-mail appender and missing hostname
78
+
79
+ == 0.7.1 / 2008-02-25
80
+
81
+ 1 minor enhancement
82
+ - Removed dependency on the Lockfile gem (brought the ruby
83
+ file into the logging/stelan directory)
84
+ 1 bug fix
85
+ - Fixed bug with age based rolling: was not multi-process safe
86
+
87
+ == 0.7.0 / 2008-02-12
88
+
89
+ 1 major enhancement
90
+ - Rails compatibility
91
+ * renamed Logger#add method to Logger#add_appenders
92
+ * renamed Logger#remove method to Logger#remove_appenders
93
+ * renamed Logger#clear method to Logger#clear_appenders
94
+ * added a new Logger#add method that conforms to the calling
95
+ semantics of the Ruby stdlib Logger
96
+
97
+ 2 minor enhancements
98
+ - Speed improvements and test coverage
99
+ - Created a top-level Logging.init method that is used to
100
+ define the default logging levels
101
+
102
+ 1 bug fix
103
+ - Tweaked windows detection code
104
+
105
+ == 0.6.3 / 2008-02-08
106
+
107
+ 2 minor enhancements
108
+ - YAML configuration now supports multiple keys -- i.e. development
109
+ or production or whatever
110
+ - Reorganized a lot of files so that requiring files is cleaner and
111
+ more deterministic
112
+
113
+ == 0.6.2 / 2008-02-06
114
+
115
+ 2 bug fixes
116
+ - An extra e-mail was being pushed out when the e-mail
117
+ appender was closed
118
+ - Created an at_exit handler to close all appenders
119
+
120
+ == 0.6.1 / 2008-01-01
121
+
122
+ 1 bug fix
123
+ - Fixed include order to avoid double loading when testing
124
+
125
+ == 0.6.0 / 2007-12-26
126
+
127
+ * Using the new 'getopt' method for handling option hashes
128
+ * Rolling file appender is safe for multiple processes
129
+ * Added an e-mail appender from Jeremy Hinegardner
130
+ * Updated tests for the appenders
131
+
132
+ == 0.5.3 / 2007-12-08
133
+
134
+ * Fixed the quoting for messages sent to the growl appender
135
+
136
+ == 0.5.2 / 2007-11-28
137
+
138
+ * Updated the library to work with Ruby 1.9
139
+ * Fixed coalescing with the growl appender
140
+
141
+ == 0.5.1 / 2007-11-18
142
+
143
+ * Fixed a bug on Windows when attempting to load the syslog library
144
+
145
+ == 0.5.0 / 2007-11-18
146
+
147
+ * Added the ability to log via the syslog daemon
148
+ * Can send messages to the Growl notification system on Mac OS X
149
+ * The Growl appender can coalesce messages of the same title/priority
150
+
151
+ == 0.4.0 / 2007-03-21
152
+
153
+ * Added a microsecond flag to the Pattern layout
154
+ * All appenders write immediately upon receipt of a logging event
155
+ * Added a basic logging method that returns a logger object configured in
156
+ the same manner as the standard Ruby logger
157
+ * Fixed a bug caused by nil log messages
158
+
159
+ == 0.3.1 / 2007-02-08
160
+
161
+ * Bugfix Release
162
+
163
+ == 0.3.0 / 2007-02-01
164
+
165
+ * Remove the ability to log multiple objects from a single log method call
166
+
167
+ == 0.2.0 / 2007-01-29
168
+
169
+ * The "once every four years" release
170
+ * Storage and retrieval of appenders by name
171
+ * YAML configuration support
172
+ * Rolling file appender
173
+
174
+ == 0.1.0 / 2007-01-12
175
+
176
+ * Birthday!
data/Manifest.txt ADDED
@@ -0,0 +1,54 @@
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/email.rb
10
+ lib/logging/appenders/file.rb
11
+ lib/logging/appenders/growl.rb
12
+ lib/logging/appenders/io.rb
13
+ lib/logging/appenders/rolling_file.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
+ lib/logging/utils.rb
24
+ tasks/ann.rake
25
+ tasks/bones.rake
26
+ tasks/gem.rake
27
+ tasks/manifest.rake
28
+ tasks/notes.rake
29
+ tasks/post_load.rake
30
+ tasks/rdoc.rake
31
+ tasks/rubyforge.rake
32
+ tasks/setup.rb
33
+ tasks/svn.rake
34
+ tasks/test.rake
35
+ test/appenders/test_console.rb
36
+ test/appenders/test_email.rb
37
+ test/appenders/test_file.rb
38
+ test/appenders/test_growl.rb
39
+ test/appenders/test_io.rb
40
+ test/appenders/test_rolling_file.rb
41
+ test/appenders/test_syslog.rb
42
+ test/benchmark.rb
43
+ test/config/test_yaml_configurator.rb
44
+ test/layouts/test_basic.rb
45
+ test/layouts/test_pattern.rb
46
+ test/setup.rb
47
+ test/test_appender.rb
48
+ test/test_layout.rb
49
+ test/test_log_event.rb
50
+ test/test_logger.rb
51
+ test/test_logging.rb
52
+ test/test_repository.rb
53
+ test/test_root_logger.rb
54
+ test/test_utils.rb
data/README.txt ADDED
@@ -0,0 +1,93 @@
1
+ Logging
2
+ by Tim Pease
3
+
4
+ * {Homepage}[http://logging.rubyforge.org/]
5
+ * {Rubyforge Project}[http://rubyforge.org/projects/logging]
6
+ * email tim dot pease at gmail dot com
7
+
8
+ == DESCRIPTION
9
+
10
+ Logging is a flexible logging library for use in Ruby programs based on the
11
+ design of Java's log4j library. It features a hierarchical logging system,
12
+ custom level names, multiple output destinations per log event, custom
13
+ formatting, and more.
14
+
15
+ == INSTALL
16
+
17
+ sudo gem install logging
18
+
19
+ == EXAMPLE
20
+
21
+ This example configures a logger to output messages in a format similar to the
22
+ core ruby Logger class. Only log messages that are warnings or higher will be
23
+ logged.
24
+
25
+ require 'logging'
26
+
27
+ logger = Logging.logger(STDOUT)
28
+ logger.level = :warn
29
+
30
+ logger.debug "this debug message will not be output by the logger"
31
+ logger.warn "this is your last warning"
32
+
33
+ In this example, a single logger is crated that will append to STDOUT and to a
34
+ file. Only log messages that are informational or higher will be logged.
35
+
36
+ require 'logging'
37
+
38
+ logger = Logging::Logger['example_logger']
39
+ logger.add_appenders(
40
+ Logging::Appender.stdout,
41
+ Logging::Appenders::File.new('example.log')
42
+ )
43
+ logger.level = :info
44
+
45
+ logger.debug "this debug message will not be output by the logger"
46
+ logger.info "just some friendly advice"
47
+
48
+ The Logging library was created to allow each class in a program to have its
49
+ own configurable logger. The logging level for a particular class can be
50
+ changed independently of all other loggers in the system. This example shows
51
+ the recommended way of accomplishing this.
52
+
53
+ require 'logging'
54
+
55
+ Logging::Logger['FirstClass'].level = :warn
56
+ Logging::Logger['SecondClass'].level = :debug
57
+
58
+ class FirstClass
59
+ def initialize
60
+ @log = Logging::Logger[self]
61
+ end
62
+
63
+ def some_method
64
+ @log.debug "some method was called on #{self.inspect}"
65
+ end
66
+ end
67
+
68
+ class SecondClass
69
+ def initialize
70
+ @log = Logging::Logger[self]
71
+ end
72
+
73
+ def another_method
74
+ @log.debug "another method was called on #{self.inspect}"
75
+ end
76
+ end
77
+
78
+ == NOTES
79
+
80
+ Although Logging is intended to supersede Log4r, it is not a one-to-one
81
+ replacement for the Log4r library. Most notably is the difference in namespaces
82
+ -- Logging vs. Log4r. Other differences include renaming Log4r::Outputter to
83
+ Logging::Appender and renaming Log4r::Formatter to Logging::Layout. These
84
+ changes were meant to bring the Logging class names more in line with the Log4j
85
+ class names.
86
+
87
+ == REQUIREMENTS
88
+
89
+ Logging does not depend on any other installed libraries or gems.
90
+
91
+ == LICENSE
92
+
93
+ Ruby
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # $Id$
2
+
3
+ load 'tasks/setup.rb'
4
+
5
+ ensure_in_path 'lib'
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.rubyforge.name = 'logging'
16
+ PROJ.rdoc.dir = 'doc/rdoc'
17
+ #PROJ.rdoc.remote_dir = 'rdoc'
18
+ PROJ.rdoc.remote_dir = ''
19
+ PROJ.version = Logging::VERSION
20
+
21
+ PROJ.exclude << %w[^tags$ ^tasks/archive ^coverage]
22
+ PROJ.rdoc.exclude << '^data'
23
+ PROJ.svn.path = ''
24
+
25
+ depend_on 'flexmock'
26
+ depend_on 'lockfile'
27
+
28
+ # EOF
data/data/logging.yaml ADDED
@@ -0,0 +1,63 @@
1
+
2
+ purpose : TestA
3
+ description: This is the 1st YAML doc
4
+ say : Hi
5
+
6
+ ---
7
+ # *** YAML2LOGGING ***
8
+ logging_config:
9
+ # define all pre config ...
10
+ pre_config:
11
+ define_levels:
12
+ - DEB
13
+ - INF
14
+ - PRT
15
+ - WRN
16
+ - ERR
17
+ - FAT
18
+ format_as : inspect
19
+ root:
20
+ level : WRN
21
+
22
+ # define all loggers ...
23
+ loggers:
24
+ - name : mylogger
25
+ level : DEB
26
+ additive : false
27
+ trace : false
28
+ appenders:
29
+ - stderr
30
+ - logfile
31
+
32
+ - name : yourlogger
33
+ level : INF
34
+ appenders:
35
+ - stderr
36
+ - logfile
37
+
38
+ # define all appenders (incl. layouts)
39
+ appenders:
40
+ - type : Stderr
41
+ name : stderr
42
+ level : DEB
43
+ layout:
44
+ type : Basic
45
+ format_as : string
46
+
47
+ - type : File
48
+ name : logfile
49
+ level : DEB
50
+ filename : 'tmp/temp.log'
51
+ truncate : true
52
+ layout:
53
+ type : Pattern
54
+ date_method : to_s
55
+ pattern : '[%d] %l %c : %m\n'
56
+
57
+ ---
58
+ purpose : TestB
59
+ description: This is the last YAML doc
60
+ say : Bye
61
+
62
+
63
+ # EOF
data/lib/logging.rb ADDED
@@ -0,0 +1,288 @@
1
+ # $Id$
2
+
3
+ # Equivalent to a header guard in C/C++
4
+ # Used to prevent the class/module from being loaded more than once
5
+ unless defined? Logging
6
+
7
+ # TODO: internal logger for debugging
8
+ # TODO: Windows Log Service appender
9
+
10
+ #
11
+ #
12
+ module Logging
13
+
14
+ # :stopdoc:
15
+ VERSION = '0.7.1'
16
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
17
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
18
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM
19
+ LEVELS = {}
20
+ LNAMES = {}
21
+ # :startdoc:
22
+
23
+ class << self
24
+
25
+ # call-seq:
26
+ # Logging.configure( filename )
27
+ #
28
+ # Configures the Logging framework using the configuration information
29
+ # found in the given file. The file extension should be either '.yaml'
30
+ # or '.yml' (XML configuration is not yet supported).
31
+ #
32
+ def configure( filename, *args )
33
+ ::Logging::Config::YamlConfigurator.load(filename, *args)
34
+ end
35
+
36
+ # call-seq:
37
+ # Logging.logger( device, age = 7, size = 1048576 )
38
+ # Logging.logger( device, age = 'weekly' )
39
+ #
40
+ # This convenience method returns a Logger instance configured to behave
41
+ # similarly to a core Ruby Logger instance.
42
+ #
43
+ # The _device_ is the logging destination. This can be a filename
44
+ # (String) or an IO object (STDERR, STDOUT, an open File, etc.). The
45
+ # _age_ is the number of old log files to keep or the frequency of
46
+ # rotation (+daily+, +weekly+, or +monthly+). The _size_ is the maximum
47
+ # logfile size and is only used when _age_ is a number.
48
+ #
49
+ # Using the same _device_ twice will result in the same Logger instance
50
+ # being returned. For example, if a Logger is created using STDOUT then
51
+ # the same Logger instance will be returned the next time STDOUT is
52
+ # used. A new Logger instance can be obtained by closing the previous
53
+ # logger instance.
54
+ #
55
+ # log1 = Logging.logger(STDOUT)
56
+ # log2 = Logging.logger(STDOUT)
57
+ # log1.object_id == log2.object_id #=> true
58
+ #
59
+ # log1.close
60
+ # log2 = Logging.logger(STDOUT)
61
+ # log1.object_id == log2.object_id #=> false
62
+ #
63
+ # The format of the log messages can be changed using a few optional
64
+ # parameters. The <tt>:pattern</tt> can be used to change the log
65
+ # message format. The <tt>:date_pattern</tt> can be used to change how
66
+ # timestamps are formatted.
67
+ #
68
+ # log = Logging.logger(STDOUT,
69
+ # :pattern => "[%d] %-5l : %m\n",
70
+ # :date_pattern => "%Y-%m-%d %H:%M:%S.%s")
71
+ #
72
+ # See the documentation for the Logging::Layouts::Pattern class for a
73
+ # full description of the :pattern and :date_pattern formatting strings.
74
+ #
75
+ def logger( *args )
76
+ opts = args.pop if args.last.instance_of?(Hash)
77
+ opts ||= Hash.new
78
+
79
+ dev = args.shift
80
+ keep = age = args.shift
81
+ size = args.shift
82
+
83
+ name = case dev
84
+ when String; dev
85
+ when File; dev.path
86
+ else dev.object_id.to_s end
87
+
88
+ repo = ::Logging::Repository.instance
89
+ return repo[name] if repo.has_logger? name
90
+
91
+ l_opts = {
92
+ :pattern => "%.1l, [%d #%p] %#{::Logging::MAX_LEVEL_LENGTH}l : %m\n",
93
+ :date_pattern => '%Y-%m-%dT%H:%M:%S.%s'
94
+ }
95
+ [:pattern, :date_pattern, :date_method].each do |o|
96
+ l_opts[o] = opts.delete(o) if opts.has_key? o
97
+ end
98
+ layout = ::Logging::Layouts::Pattern.new(l_opts)
99
+
100
+ a_opts = Hash.new
101
+ a_opts[:size] = size if size.instance_of?(Fixnum)
102
+ a_opts[:age] = age if age.instance_of?(String)
103
+ a_opts[:keep] = keep if keep.instance_of?(Fixnum)
104
+ a_opts[:filename] = dev if dev.instance_of?(String)
105
+ a_opts[:layout] = layout
106
+ a_opts.merge! opts
107
+
108
+ appender =
109
+ case dev
110
+ when String
111
+ ::Logging::Appenders::RollingFile.new(name, a_opts)
112
+ else
113
+ ::Logging::Appenders::IO.new(name, dev, a_opts)
114
+ end
115
+
116
+ logger = ::Logging::Logger.new(name)
117
+ logger.add_appenders appender
118
+ logger.additive = false
119
+
120
+ class << logger
121
+ def close
122
+ @appenders.each {|a| a.close}
123
+ h = ::Logging::Repository.instance.instance_variable_get :@h
124
+ h.delete(@name)
125
+ class << self; undef :close; end
126
+ end
127
+ end
128
+
129
+ logger
130
+ end
131
+
132
+ # call-seq:
133
+ # Logging.init( levels )
134
+ #
135
+ # Defines the levels available to the loggers. The _levels_ is an array
136
+ # of strings and symbols. Each element in the array is downcased and
137
+ # converted to a symbol; these symbols are used to create the logging
138
+ # methods in the loggers.
139
+ #
140
+ # The first element in the array is the lowest logging level. Setting the
141
+ # logging level to this value will enable all log messages. The last
142
+ # element in the array is the highest logging level. Setting the logging
143
+ # level to this value will disable all log messages except this highest
144
+ # level.
145
+ #
146
+ # This method should only be invoked once to configure the logging
147
+ # levels. It is automatically invoked with the default logging levels
148
+ # when the first logger is created.
149
+ #
150
+ # The levels "all" and "off" are reserved and will be ignored if passed
151
+ # to this method.
152
+ #
153
+ # Example:
154
+ #
155
+ # Logging.init :debug, :info, :warn, :error, :fatal
156
+ # log = Logging::Logger['my logger']
157
+ # log.level = :warn
158
+ # log.warn 'Danger! Danger! Will Robinson'
159
+ # log.info 'Just FYI' # => not logged
160
+ #
161
+ # or
162
+ #
163
+ # Logging.init %w(DEBUG INFO NOTICE WARNING ERR CRIT ALERT EMERG)
164
+ # log = Logging::Logger['syslog']
165
+ # log.level = :notice
166
+ # log.warning 'This is your first warning'
167
+ # log.info 'Just FYI' # => not logged
168
+ #
169
+ def init( *args )
170
+ args = %w(debug info warn error fatal) if args.empty?
171
+
172
+ args.flatten!
173
+ levels = ::Logging::LEVELS.clear
174
+ names = ::Logging::LNAMES.clear
175
+
176
+ id = 0
177
+ args.each do |lvl|
178
+ lvl = levelify lvl
179
+ unless levels.has_key?(lvl) or lvl == 'all' or lvl == 'off'
180
+ levels[lvl] = id
181
+ names[id] = lvl.upcase
182
+ id += 1
183
+ end
184
+ end
185
+
186
+ longest = names.values.inject {|x,y| (x.length > y.length) ? x : y}
187
+ module_eval "MAX_LEVEL_LENGTH = #{longest.length}"
188
+
189
+ levels.keys
190
+ end
191
+
192
+ # call-seq:
193
+ # Logging.format_as( obj_format )
194
+ #
195
+ # Defines the default _obj_format_ method to use when converting objects
196
+ # into string representations for logging. _obj_format_ can be one of
197
+ # <tt>:string</tt>, <tt>:inspect</tt>, or <tt>:yaml</tt>. These
198
+ # formatting commands map to the following object methods
199
+ #
200
+ # * :string => to_s
201
+ # * :inspect => inspect
202
+ # * :yaml => to_yaml
203
+ #
204
+ # An +ArgumentError+ is raised if anything other than +:string+,
205
+ # +:inspect+, +:yaml+ is passed to this method.
206
+ #
207
+ def format_as( f )
208
+ f = f.intern if f.instance_of? String
209
+
210
+ unless [:string, :inspect, :yaml].include? f
211
+ raise ArgumentError, "unknown object format '#{f}'"
212
+ end
213
+
214
+ module_eval "OBJ_FORMAT = :#{f}"
215
+ end
216
+
217
+ # Returns the version string for the library.
218
+ #
219
+ def version
220
+ VERSION
221
+ end
222
+
223
+ # Returns the library path for the module. If any arguments are given,
224
+ # they will be joined to the end of the libray path using
225
+ # <tt>File.join</tt>.
226
+ #
227
+ def libpath( *args )
228
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
229
+ end
230
+
231
+ # Returns the lpath for the module. If any arguments are given,
232
+ # they will be joined to the end of the path using
233
+ # <tt>File.join</tt>.
234
+ #
235
+ def path( *args )
236
+ args.empty? ? PATH : ::File.join(PATH, *args)
237
+ end
238
+
239
+ # Utility method used to rquire all files ending in .rb that lie in the
240
+ # directory below this file that has the same name as the filename passed
241
+ # in. Optionally, a specific _directory_ name can be passed in such that
242
+ # the _filename_ does not have to be equivalent to the directory.
243
+ #
244
+ def require_all_libs_relative_to( fname, dir = nil )
245
+ dir ||= ::File.basename(fname, '.*')
246
+ search_me = ::File.expand_path(
247
+ ::File.join(::File.dirname(fname), dir, '*.rb'))
248
+
249
+ Dir.glob(search_me).sort.each {|rb| require rb}
250
+ end
251
+
252
+ # :stopdoc:
253
+ # Convert the given level into a connaconical form - a lowercase string.
254
+ def levelify( level )
255
+ case level
256
+ when String; level.downcase
257
+ when Symbol; level.to_s.downcase
258
+ else raise ArgumentError, "levels must be a String or Symbol" end
259
+ end
260
+
261
+ # Convert the given level into a level number.
262
+ def level_num( level )
263
+ l = levelify level
264
+ case l
265
+ when 'all'; 0
266
+ when 'off'; LEVELS.length
267
+ else begin; Integer(l); rescue ArgumentError; LEVELS[l] end end
268
+ end
269
+ # :startdoc:
270
+ end
271
+ end # module Logging
272
+
273
+ Logging.require_all_libs_relative_to(__FILE__)
274
+ Logging.require_all_libs_relative_to(__FILE__, 'logging/config')
275
+
276
+ # This exit handler will close all the appenders that exist in the system.
277
+ # This is needed for closing IO streams and connections to the syslog server
278
+ # or e-mail servers, etc.
279
+ #
280
+ at_exit {
281
+ Logging::Appender.instance_variable_get(:@appenders).values.each do |ap|
282
+ ap.close
283
+ end
284
+ }
285
+
286
+ end # unless defined?
287
+
288
+ # EOF