mtn_log4r 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +15 -0
  2. data/doc/content/contact.html +22 -0
  3. data/doc/content/contribute.html +21 -0
  4. data/doc/content/index.html +90 -0
  5. data/doc/content/license.html +56 -0
  6. data/doc/content/manual.html +449 -0
  7. data/doc/dev/README.developers +55 -0
  8. data/doc/dev/checklist +23 -0
  9. data/doc/dev/things-to-do +5 -0
  10. data/doc/images/log4r-logo.png +0 -0
  11. data/doc/images/logo2.png +0 -0
  12. data/doc/log4r.css +111 -0
  13. data/doc/rdoc-log4r.css +696 -0
  14. data/doc/templates/main.html +147 -0
  15. data/examples/README +19 -0
  16. data/examples/ancestors.rb +53 -0
  17. data/examples/chainsaw_settings.xml +7 -0
  18. data/examples/customlevels.rb +34 -0
  19. data/examples/filelog.rb +25 -0
  20. data/examples/fileroll.rb +40 -0
  21. data/examples/gmail.rb +30 -0
  22. data/examples/gmail.yaml +95 -0
  23. data/examples/log4r_yaml.yaml +0 -0
  24. data/examples/logclient.rb +25 -0
  25. data/examples/logserver.rb +18 -0
  26. data/examples/moderate.xml +29 -0
  27. data/examples/moderateconfig.rb +66 -0
  28. data/examples/myformatter.rb +23 -0
  29. data/examples/outofthebox.rb +21 -0
  30. data/examples/rdoc-gen +2 -0
  31. data/examples/rrconfig.xml +63 -0
  32. data/examples/rrsetup.rb +42 -0
  33. data/examples/simpleconfig.rb +39 -0
  34. data/examples/syslogcustom.rb +52 -0
  35. data/examples/xmlconfig.rb +25 -0
  36. data/examples/yaml.rb +30 -0
  37. data/lib/log4r/GDC.rb +41 -0
  38. data/lib/log4r/MDC.rb +59 -0
  39. data/lib/log4r/NDC.rb +86 -0
  40. data/lib/log4r/base.rb +74 -0
  41. data/lib/log4r/config.rb +9 -0
  42. data/lib/log4r/configurator.rb +224 -0
  43. data/lib/log4r/formatter/formatter.rb +109 -0
  44. data/lib/log4r/formatter/log4jxmlformatter.rb +65 -0
  45. data/lib/log4r/formatter/patternformatter.rb +145 -0
  46. data/lib/log4r/lib/drbloader.rb +52 -0
  47. data/lib/log4r/lib/xmlloader.rb +24 -0
  48. data/lib/log4r/logevent.rb +28 -0
  49. data/lib/log4r/logger.rb +199 -0
  50. data/lib/log4r/loggerfactory.rb +89 -0
  51. data/lib/log4r/logserver.rb +28 -0
  52. data/lib/log4r/outputter/consoleoutputters.rb +18 -0
  53. data/lib/log4r/outputter/datefileoutputter.rb +117 -0
  54. data/lib/log4r/outputter/emailoutputter.rb +143 -0
  55. data/lib/log4r/outputter/fileoutputter.rb +56 -0
  56. data/lib/log4r/outputter/iooutputter.rb +55 -0
  57. data/lib/log4r/outputter/outputter.rb +134 -0
  58. data/lib/log4r/outputter/outputterfactory.rb +61 -0
  59. data/lib/log4r/outputter/rabbitoutputter.rb +70 -0
  60. data/lib/log4r/outputter/remoteoutputter.rb +40 -0
  61. data/lib/log4r/outputter/rollingfileoutputter.rb +234 -0
  62. data/lib/log4r/outputter/scribeoutputter.rb +37 -0
  63. data/lib/log4r/outputter/staticoutputter.rb +30 -0
  64. data/lib/log4r/outputter/syslogoutputter.rb +130 -0
  65. data/lib/log4r/outputter/udpoutputter.rb +53 -0
  66. data/lib/log4r/rdoc/GDC +14 -0
  67. data/lib/log4r/rdoc/MDC +16 -0
  68. data/lib/log4r/rdoc/NDC +41 -0
  69. data/lib/log4r/rdoc/configurator +243 -0
  70. data/lib/log4r/rdoc/emailoutputter +103 -0
  71. data/lib/log4r/rdoc/formatter +39 -0
  72. data/lib/log4r/rdoc/log4jxmlformatter +21 -0
  73. data/lib/log4r/rdoc/log4r +89 -0
  74. data/lib/log4r/rdoc/logger +175 -0
  75. data/lib/log4r/rdoc/logserver +85 -0
  76. data/lib/log4r/rdoc/outputter +108 -0
  77. data/lib/log4r/rdoc/patternformatter +128 -0
  78. data/lib/log4r/rdoc/scribeoutputter +16 -0
  79. data/lib/log4r/rdoc/syslogoutputter +29 -0
  80. data/lib/log4r/rdoc/win32eventoutputter +7 -0
  81. data/lib/log4r/rdoc/yamlconfigurator +20 -0
  82. data/lib/log4r/repository.rb +88 -0
  83. data/lib/log4r/staticlogger.rb +49 -0
  84. data/lib/log4r/version.rb +4 -0
  85. data/lib/log4r/yamlconfigurator.rb +198 -0
  86. data/lib/log4r.rb +18 -0
  87. data/tests/README +10 -0
  88. data/tests/testGDC.rb +24 -0
  89. data/tests/testMDC.rb +40 -0
  90. data/tests/testNDC.rb +25 -0
  91. data/tests/test_helper.rb +12 -0
  92. data/tests/testall.rb +6 -0
  93. data/tests/testbase.rb +48 -0
  94. data/tests/testchainsaw.rb +42 -0
  95. data/tests/testconf.xml +37 -0
  96. data/tests/testcustom.rb +30 -0
  97. data/tests/testformatter.rb +31 -0
  98. data/tests/testlogger.rb +200 -0
  99. data/tests/testoutputter.rb +143 -0
  100. data/tests/testpatternformatter.rb +76 -0
  101. data/tests/testthreads.rb +31 -0
  102. data/tests/testxmlconf.rb +48 -0
  103. data/tests/testyaml.rb +39 -0
  104. data/tests/testyaml_arrays.yaml +25 -0
  105. data/tests/testyaml_injection.yaml +22 -0
  106. metadata +193 -0
@@ -0,0 +1,63 @@
1
+ <!-- This is a real config file used by a game that I'm working on
2
+ The Ruby file that loads this is rrsetup.rb -->
3
+ <log4r_config>
4
+ <pre_config>
5
+ <!-- I like having a ton of levels. There are three extra for component
6
+ data, comp1..3 and one level for object dumps (DATA) -->
7
+ <custom_levels>
8
+ COMP3, COMP2, COMP1, DATA, DEBUG, INFO, WARN, ERROR, FATAL
9
+ </custom_levels>
10
+ <!-- change to ERROR when the game goes to production -->
11
+ <global level="ALL"/>
12
+ </pre_config>
13
+
14
+ <!-- Outputters -->
15
+
16
+ <!-- game.log records DEBUG and higher, so no game component data -->
17
+ <outputter name="gameout" type="FileOutputter" level="DEBUG">
18
+ <!-- I set the logpath from within the game. -->
19
+ <filename>#{logpath}/game.log</filename>
20
+ </outputter>
21
+ <!-- DATA level goes to its own special file. These log events are
22
+ too noisy for game.log and are not game components. Useful
23
+ for dumping lots of objects during development. -->
24
+ <outputter name="gamedata" type="FileOutputter" only_at="DATA">
25
+ <filename>#{logpath}/data.log</filename>
26
+ <!-- low-noise custom formatter for objects -->
27
+ <formatter type="CompFormatter"/>
28
+ </outputter>
29
+ <!-- Spit any errors to the console. They merit special attention -->
30
+ <outputter name="console" type="StderrOutputter" level="ERROR"/>
31
+ <!-- A separate log file for tracking game components,
32
+ used for development. It logs ALL-->
33
+ <outputter name="componentout" type="FileOutputter">
34
+ <filename>#{logpath}/component.log</filename>
35
+ <formatter type="CompFormatter"/>
36
+ </outputter>
37
+
38
+ <!-- Loggers -->
39
+
40
+ <!-- 'game' is the main logger for the client-server framework -->
41
+ <logger name="game" level="DATA" additive="false" trace="true">
42
+ <outputters>gameout, gamedata, console</outputters>
43
+ </logger>
44
+ <!-- Notice how we have fine control over how each element logs.
45
+ The gui and controller are stable while the rest are being debugged. -->
46
+ <logger name="game::gui" level="ERROR" additive="true" trace="true"/>
47
+ <logger name="game::boardgui" level="DEBUG" additive="true" trace="false"/>
48
+ <logger name="game::server" level="DEBUG" additive="true" trace="true"/>
49
+ <logger name="game::client" level="DEBUG" additive="true" trace="true"/>
50
+ <logger name="game::controller" level="ERROR" additive="true" trace="false"/>
51
+
52
+ <!-- 'component' is the main logger for game objects. It's used in
53
+ development to track how the objects change with time. -->
54
+ <logger name="component" level="ALL" additive="false" trace="false">
55
+ <outputter>componentout</outputter>
56
+ <outputter>console</outputter>
57
+ </logger>
58
+ <logger name="component::board"/>
59
+ <logger name="component::tile"/>
60
+ <logger name="component::player"/>
61
+ <logger name="component::player::robot"/>
62
+
63
+ </log4r_config>
@@ -0,0 +1,42 @@
1
+ # This is a real config file used by a game that I'm working on
2
+ # The XML config file is called rrconfig.xml
3
+
4
+ $: << File.join('..','lib')
5
+ require 'log4r'
6
+ require 'log4r/configurator'
7
+ include Log4r
8
+
9
+ # How to format component data - low noise
10
+ class CompFormatter < Formatter
11
+ def format(event)
12
+ buff = event.name + "> "
13
+ if event.data.kind_of?(String) then buff += event.data
14
+ else buff += event.data.inspect end
15
+ return buff + "\n"
16
+ end
17
+ end
18
+
19
+ # Set the logpath. Eventually, this will be determined from the environment.
20
+ Configurator['logpath'] = './logs'
21
+ Configurator.load_xml_file('rrconfig.xml')
22
+
23
+ # the rest is an example
24
+
25
+ Robot = {"name"=>"twonky", "row"=>"3", "col"=>"4"}
26
+
27
+ def do_logging(log)
28
+ log.comp3 Robot
29
+ log.comp2 Robot
30
+ log.comp1 Robot
31
+ log.data "this is a piece of data".split
32
+ log.debug "debugging"
33
+ log.info "a piece of info"
34
+ log.warn "Danger, Will Robinson, danger!"
35
+ log.error "I dropped my Wookie! :("
36
+ log.fatal "kaboom!"
37
+ end
38
+
39
+ Logger.each_logger {|logger| do_logging(logger)}
40
+
41
+ # you can see the results onscreen and in logs/game.log
42
+ # logs/data.log and logs/component.log
@@ -0,0 +1,39 @@
1
+ # Simple configuration example.
2
+ # Where we configure just one logger and make it log to a file and stdout.
3
+
4
+ # add the path to log4r if it isn't installed in a ruby path
5
+ $: << File.join('..','lib')
6
+ require "log4r"
7
+
8
+ # First things first, get the root logger and set its level to WARN.
9
+ # This makes the global level WARN. Later on, we can turn off all logging
10
+ # by setting it to OFF right here (or dynamically if you prefer)
11
+ Log4r::Logger.root.level = Log4r::WARN
12
+
13
+ # Remember: By specifying a level, we are saying "Include this level and
14
+ # anything worse." So in this case, we're logging WARN, ERROR and FATAL
15
+
16
+ # create a logger
17
+ log = Log4r::Logger.new("simpleconf")
18
+
19
+ # We want to log to $stderr and a file ./tmp.log
20
+
21
+ # Create an outputter for $stderr. It defaults to the root level WARN
22
+ Log4r::StderrOutputter.new 'console'
23
+ # for the file, we want to log only FATAL and ERROR and don't trunc
24
+ Log4r::FileOutputter.new('logfile',
25
+ :filename=>'logs/simple.log',
26
+ :trunc=>false,
27
+ :level=>Log4r::FATAL)
28
+
29
+ # add the outputters (this method accepts outputter names or references)
30
+ log.add('console','logfile')
31
+
32
+ # Now let's try it out:
33
+ log.debug "debugging"
34
+ log.info "a piece of info"
35
+ log.warn "Danger, Will Robinson, danger!"
36
+ log.error "I dropped my Wookie! :("
37
+ log.fatal "kaboom!"
38
+
39
+ # now run this and compare output to ./tmp.log
@@ -0,0 +1,52 @@
1
+ # Suppose we don't like having 5 levels named DEBUG, INFO, etc.
2
+ # Suppose we'd rather use 3 levels named Foo, Bar, and Baz.
3
+ # Suppose we'd like to use these with syslog
4
+ # Log4r allows you to rename the levels and their corresponding methods
5
+ # in a painless way and then map those to corrisponding syslog levels
6
+ # or have them all default to LOG_INFO
7
+ # This file provides an example
8
+
9
+ $: << '../lib'
10
+
11
+ require 'log4r'
12
+ require 'log4r/configurator'
13
+ require 'log4r/formatter/patternformatter'
14
+ require 'log4r/outputter/syslogoutputter'
15
+ require 'syslog'
16
+ include Log4r
17
+ include Syslog::Constants
18
+
19
+ # This is how we specify our levels
20
+ Configurator.custom_levels "Foo", "Bar", "Baz"
21
+
22
+ l = Logger.new('custom levels')
23
+ slp = PatternFormatter.new( :pattern => '{%p} {%h} {%d} {%l} {%C} {%m}', :date_method => 'usec' )
24
+ sl = SyslogOutputter.new( 'sysloggertest',
25
+ { :logopt => LOG_CONS | LOG_PID | LOG_PERROR,
26
+ :facility => LOG_LOCAL7,
27
+ :formatter => slp } )
28
+ sl.map_levels_by_name_to_syslog( { "Foo" => "DEBUG", "Bar" => "INFO", "Baz" => "ALERT" } )
29
+ l.add sl
30
+
31
+ l.level = Foo
32
+ puts l.foo?
33
+ l.foo "This is foo"
34
+ puts l.bar?
35
+ l.bar "this is bar"
36
+ puts l.baz?
37
+ l.baz "this is baz"
38
+
39
+ puts "Now change to Baz"
40
+
41
+ l.level = Baz
42
+ puts l.foo?
43
+ l.foo {"This is foo"}
44
+ puts l.bar?
45
+ l.bar {"this is bar"}
46
+ puts l.baz?
47
+ l.baz {"this is baz"}
48
+
49
+ l4r = Logger.new('log4r')
50
+ l4r.add Log4r::Outputter.stderr
51
+
52
+ Log4r::SyslogOutputter.new 'test'
@@ -0,0 +1,25 @@
1
+ # This is like moderateconfig.rb, but using an XML config
2
+ # please look at moderate.xml
3
+
4
+ $: << '../lib'
5
+
6
+ require 'log4r'
7
+ require 'log4r/configurator'
8
+ include Log4r
9
+
10
+ # set any runtime XML variables
11
+ Configurator['logpath'] = './logs'
12
+ # Load up the config file
13
+ Configurator.load_xml_file('./moderate.xml')
14
+
15
+ # now repeat what moderateconfig.rb does
16
+ def do_logging(log)
17
+ log.debug "debugging"
18
+ log.info "a piece of info"
19
+ log.warn "Danger, Will Robinson, danger!"
20
+ log.error "I dropped my Wookie! :("
21
+ log.fatal "kaboom!"
22
+ end
23
+
24
+ Logger.each_logger{|logger| do_logging(logger) }
25
+ # stop here
data/examples/yaml.rb ADDED
@@ -0,0 +1,30 @@
1
+ # Log4r can be configured using YAML. This example uses log4r_yaml.yaml
2
+
3
+ $: << File.join('..','lib') # path if log4r is not installed
4
+ require 'log4r'
5
+ require 'log4r/yamlconfigurator'
6
+ # we use various outputters, so require them, otherwise config chokes
7
+ require 'log4r/outputter/datefileoutputter'
8
+ require 'log4r/outputter/emailoutputter'
9
+ require 'log4r/outputter/scribeoutputter'
10
+
11
+ cfg = Log4r::YamlConfigurator # shorthand
12
+ cfg['HOME'] = '.' # the only parameter in the YAML, our HOME directory
13
+
14
+ # load the YAML file with this
15
+ cfg.load_yaml_file('log4r_yaml.yaml')
16
+
17
+ # Method to log each of the custom levels
18
+ def do_logging(log)
19
+ log.deb "This is DEB"
20
+ log.inf "This is INF"
21
+ log.prt "This is PRT"
22
+ log.wrn "This is WRN"
23
+ log.err "This is ERR"
24
+ log.fat "This is FAT"
25
+ end
26
+
27
+ # turn off the email outputter
28
+ Log4r::Outputter['email'].level = Log4r::OFF
29
+ # the other two outputters log to stderr and a timestamped file in ./logs
30
+ do_logging( Log4r::Logger['mylogger'])
data/lib/log4r/GDC.rb ADDED
@@ -0,0 +1,41 @@
1
+ # :include: rdoc/GDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id$
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ require 'monitor'
9
+
10
+ module Log4r
11
+ GDCNAME = "log4rGDC"
12
+ $globalGDCLock = Monitor.new
13
+
14
+ # See log4r/GDC.rb
15
+ class GDC < Monitor
16
+ private_class_method :new
17
+
18
+ def self.clear()
19
+ Thread.main[GDCNAME] = ""
20
+ end
21
+
22
+ def self.get()
23
+ $globalGDCLock.synchronize do
24
+ if ( Thread.main[GDCNAME] == nil ) then
25
+ Thread.main[GDCNAME] = $0
26
+ end
27
+ end
28
+ return Thread.main[GDCNAME]
29
+ end
30
+
31
+ def self.set( a_name )
32
+ if ( Thread.current != Thread.main ) then
33
+ raise "Can only initialize Global Diagnostic Context from Thread.main"
34
+ end
35
+ $globalGDCLock.synchronize do
36
+ Thread.main[GDCNAME] = a_name
37
+ end
38
+ end
39
+ end
40
+ end
41
+
data/lib/log4r/MDC.rb ADDED
@@ -0,0 +1,59 @@
1
+ # :include: rdoc/MDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id$
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ require 'monitor'
9
+
10
+ module Log4r
11
+ MDCNAME = "log4rMDC"
12
+ MDCNAMEMAXDEPTH = "log4rMDCMAXDEPTH"
13
+ $globalMDCLock = Monitor.new
14
+
15
+ # See log4r/MDC.rb
16
+ class MDC < Monitor
17
+ private_class_method :new
18
+
19
+ def self.check_thread_instance()
20
+ # need to interlock here, so that if
21
+ # another thread is entering this section
22
+ # of code before the main thread does,
23
+ # then the main thread copy of the MDC
24
+ # is setup before then attempting to clone
25
+ # it off
26
+ if ( Thread.current[MDCNAME] == nil ) then
27
+ $globalMDCLock.synchronize do
28
+ if ( Thread.main[MDCNAME] == nil ) then
29
+ Thread.main[MDCNAME] = Hash.new
30
+ end
31
+ if ( Thread.current != Thread.main ) then
32
+ Thread.current[MDCNAME] = Hash.new
33
+ Thread.main[MDCNAME].each{ |k,v| Thread.current[MDCNAME][k] = v }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.get( a_key )
40
+ self.check_thread_instance()
41
+ Thread.current[MDCNAME].fetch(a_key, "");
42
+ end
43
+
44
+ def self.get_context()
45
+ self.check_thread_instance()
46
+ return Thread.current[MDCNAME].clone
47
+ end
48
+
49
+ def self.put( a_key, a_value )
50
+ self.check_thread_instance()
51
+ Thread.current[MDCNAME][a_key] = a_value
52
+ end
53
+
54
+ def self.remove( a_key )
55
+ self.check_thread_instance()
56
+ Thread.current[MDCNAME].delete( a_key )
57
+ end
58
+ end
59
+ end
data/lib/log4r/NDC.rb ADDED
@@ -0,0 +1,86 @@
1
+ # :include: rdoc/NDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id$
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ module Log4r
9
+ NDCNAME = "log4rNDC"
10
+ NDCNAMEMAXDEPTH = "log4rNDCMAXDEPTH"
11
+ NDCDEFAULTMAXDEPTH = 256
12
+
13
+ # See log4r/NDC.rb
14
+ class NDC
15
+ private_class_method :new
16
+
17
+ def self.check_thread_instance()
18
+ if ( Thread.current[NDCNAME] == nil ) then
19
+ Thread.current[NDCNAME] = Array.new
20
+ Thread.current[NDCNAMEMAXDEPTH] = NDCDEFAULTMAXDEPTH
21
+ end
22
+ end
23
+
24
+ def self.clear()
25
+ self.check_thread_instance()
26
+ Thread.current[NDCNAME].clear
27
+ end
28
+
29
+ def self.clone_stack()
30
+ self.check_thread_instance()
31
+ return Thread.current[NDCNAME].clone
32
+ end
33
+
34
+ def self.get_depth()
35
+ self.check_thread_instance()
36
+ return Thread.current[NDCNAME].length
37
+ end
38
+
39
+ def self.inherit( a_stack )
40
+ if ( a_stack.class == Array ) then
41
+ if ( Thread.current[NDCNAME] != nil ) then
42
+ Thread.current[NDCNAME].clear
43
+ Thread.current[NDCNAME] = nil
44
+ end
45
+ Thread.current[NDCNAME] = a_stack
46
+ else
47
+ raise "Expecting Array in NDC.inherit"
48
+ end
49
+ end
50
+
51
+ def self.get()
52
+ self.check_thread_instance
53
+ return Thread.current[NDCNAME] * " "
54
+ end
55
+
56
+ def self.peek()
57
+ self.check_thread_instance()
58
+ return Thread.current[NDCNAME].last
59
+ end
60
+
61
+ def self.pop()
62
+ self.check_thread_instance()
63
+ return Thread.current[NDCNAME].pop
64
+ end
65
+
66
+ def self.push( value )
67
+ self.check_thread_instance()
68
+ if ( Thread.current[NDCNAME].length < Thread.current[NDCNAMEMAXDEPTH] ) then
69
+ Thread.current[NDCNAME].push( value )
70
+ end
71
+ end
72
+
73
+ def self.remove()
74
+ self.check_thread_instance()
75
+ Thread.current[NDCNAME].clear
76
+ Thread.current[NDCNAMEMAXDEPTH] = nil
77
+ Thread.current[NDCNAME] = nil
78
+ end
79
+
80
+ def self.set_max_depth( max_depth )
81
+ self.check_thread_instance()
82
+ Thread.current[NDCNAMEMAXDEPTH] = max_depth
83
+ end
84
+ end
85
+ end
86
+
data/lib/log4r/base.rb ADDED
@@ -0,0 +1,74 @@
1
+ # :nodoc:
2
+ require "log4r/config"
3
+
4
+ module Log4r
5
+ ALL = 0
6
+ LNAMES = ['ALL']
7
+
8
+ # Defines the log levels of the Log4r module at runtime. It is given
9
+ # either the default level spec (when root logger is created) or the
10
+ # user-specified level spec (when Logger.custom_levels is called).
11
+ #
12
+ # The last constant defined by this method is OFF. Other level-sensitive
13
+ # parts of the code check to see if OFF is defined before deciding what
14
+ # to do. The typical action would be to force the creation of RootLogger
15
+ # so that the custom levels get loaded and business can proceed as usual.
16
+ #
17
+ # For purposes of formatting, a constant named MaxLevelLength is defined
18
+ # in this method. It stores the max level name string size.
19
+
20
+ def Log4r.define_levels(*levels) #:nodoc:
21
+ return if const_defined? :OFF
22
+ for i in 0...levels.size
23
+ name = levels[i].to_s
24
+ module_eval "#{name} = #{i} + 1; LNAMES.push '#{name}'"
25
+ end
26
+ module_eval %{
27
+ LNAMES.push 'OFF'
28
+ LEVELS = LNAMES.size
29
+ OFF = LEVELS - 1
30
+ MaxLevelLength = Log4rTools.max_level_str_size
31
+ }
32
+ end
33
+
34
+ # Some common functions
35
+ class Log4rTools
36
+ # Raises ArgumentError if level argument is an invalid level. Depth
37
+ # specifies how many trace entries to remove.
38
+ def self.validate_level(level, depth=0)
39
+ unless valid_level?(level)
40
+ raise ArgumentError, "Log level must be in 0..#{LEVELS}",
41
+ caller[1..-(depth + 1)]
42
+ end
43
+ end
44
+
45
+ def self.valid_level?(lev)
46
+ not lev.nil? and lev.kind_of?(Numeric) and lev >= ALL and lev <= OFF
47
+ end
48
+
49
+ def self.max_level_str_size #:nodoc:
50
+ size = 0
51
+ LNAMES.each {|i| size = i.length if i.length > size}
52
+ size
53
+ end
54
+
55
+ # Shortcut for decoding 'true', 'false', true, false or nil into a bool
56
+ # from a hash parameter. E.g., it looks for true/false values for
57
+ # the keys 'symbol' and :symbol.
58
+
59
+ def self.decode_bool(hash, symbol, default)
60
+ data = hash[symbol]
61
+ data = hash[symbol.to_s] if data.nil?
62
+ return case data
63
+ when 'true',true then true
64
+ when 'false',false then false
65
+ else default
66
+ end
67
+ end
68
+
69
+ # Splits comma-delimited lists with arbitrary \s padding
70
+ def self.comma_split(string)
71
+ string.split(/\s*,\s*/).collect {|s| s.strip}
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,9 @@
1
+ # :nodoc:
2
+ # Version:: $Id$
3
+
4
+ module Log4r
5
+ module Log4rConfig #:nodoc:
6
+ LogLevels = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
7
+ LoggerPathDelimiter = '::'
8
+ end
9
+ end