log4r 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/content/contact.html +22 -0
- data/doc/content/contribute.html +21 -0
- data/doc/content/index.html +90 -0
- data/doc/content/license.html +56 -0
- data/doc/content/manual.html +449 -0
- data/doc/dev/README.developers +55 -0
- data/doc/dev/checklist +23 -0
- data/doc/dev/things-to-do +5 -0
- data/doc/images/log4r-logo.png +0 -0
- data/doc/images/logo2.png +0 -0
- data/doc/log4r.css +111 -0
- data/doc/templates/main.html +147 -0
- data/examples/README +19 -0
- data/examples/customlevels.rb +34 -0
- data/examples/fileroll.rb +40 -0
- data/examples/log4r_yaml.yaml +0 -0
- data/examples/logclient.rb +25 -0
- data/examples/logserver.rb +18 -0
- data/examples/moderate.xml +29 -0
- data/examples/moderateconfig.rb +66 -0
- data/examples/myformatter.rb +23 -0
- data/examples/outofthebox.rb +21 -0
- data/examples/rrconfig.xml +63 -0
- data/examples/rrsetup.rb +42 -0
- data/examples/simpleconfig.rb +39 -0
- data/examples/xmlconfig.rb +25 -0
- data/examples/yaml.rb +30 -0
- data/src/log4r.rb +17 -0
- data/src/log4r/base.rb +74 -0
- data/src/log4r/config.rb +9 -0
- data/src/log4r/configurator.rb +224 -0
- data/src/log4r/formatter/formatter.rb +105 -0
- data/src/log4r/formatter/patternformatter.rb +107 -0
- data/src/log4r/lib/drbloader.rb +52 -0
- data/src/log4r/lib/xmlloader.rb +24 -0
- data/src/log4r/logevent.rb +28 -0
- data/src/log4r/logger.rb +194 -0
- data/src/log4r/loggerfactory.rb +89 -0
- data/src/log4r/logserver.rb +28 -0
- data/src/log4r/outputter/consoleoutputters.rb +18 -0
- data/src/log4r/outputter/datefileoutputter.rb +110 -0
- data/src/log4r/outputter/emailoutputter.rb +116 -0
- data/src/log4r/outputter/fileoutputter.rb +49 -0
- data/src/log4r/outputter/iooutputter.rb +55 -0
- data/src/log4r/outputter/outputter.rb +132 -0
- data/src/log4r/outputter/outputterfactory.rb +59 -0
- data/src/log4r/outputter/remoteoutputter.rb +40 -0
- data/src/log4r/outputter/rollingfileoutputter.rb +126 -0
- data/src/log4r/outputter/staticoutputter.rb +30 -0
- data/src/log4r/outputter/syslogoutputter.rb +75 -0
- data/src/log4r/rdoc/configurator +243 -0
- data/src/log4r/rdoc/emailoutputter +103 -0
- data/src/log4r/rdoc/formatter +39 -0
- data/src/log4r/rdoc/log4r +89 -0
- data/src/log4r/rdoc/logger +175 -0
- data/src/log4r/rdoc/logserver +85 -0
- data/src/log4r/rdoc/outputter +108 -0
- data/src/log4r/rdoc/patternformatter +128 -0
- data/src/log4r/rdoc/syslogoutputter +29 -0
- data/src/log4r/rdoc/yamlconfigurator +20 -0
- data/src/log4r/repository.rb +65 -0
- data/src/log4r/staticlogger.rb +49 -0
- data/src/log4r/yamlconfigurator.rb +0 -0
- data/tests/README +10 -0
- data/tests/testall.rb +6 -0
- data/tests/testbase.rb +49 -0
- data/tests/testconf.xml +37 -0
- data/tests/testcustom.rb +27 -0
- data/tests/testformatter.rb +27 -0
- data/tests/testlogger.rb +196 -0
- data/tests/testoutputter.rb +111 -0
- data/tests/testpatternformatter.rb +21 -0
- data/tests/testxmlconf.rb +45 -0
- metadata +127 -0
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# How to use RemoteOutputter. See logserver.rb first.
|
2
|
+
|
3
|
+
$: << File.join('..','src')
|
4
|
+
require 'log4r'
|
5
|
+
require 'log4r/outputter/remoteoutputter'
|
6
|
+
include Log4r
|
7
|
+
|
8
|
+
Logger.new('log4r').add 'stdout' # to see what's going on inside
|
9
|
+
RemoteOutputter.new 'remote', # make a RemoteOutputter
|
10
|
+
:uri=>'tcpromp://localhost:9999', # where our LogServer is
|
11
|
+
:buffsize=>10 # buffer 10 before sending to LogServer
|
12
|
+
Logger.new('client').add('remote') # give 'remote' to a 'client' Logger
|
13
|
+
|
14
|
+
# we're done with setup, now let's log
|
15
|
+
def log(l)
|
16
|
+
l.debug "debugging"
|
17
|
+
l.info "a piece of info"
|
18
|
+
l.warn "Danger, Will Robinson, danger!"
|
19
|
+
l.error "I dropped by Wookie! :("
|
20
|
+
l.fatal "kaboom!"
|
21
|
+
end
|
22
|
+
|
23
|
+
5.times { log(Logger['client']) } # do a bunch of logging
|
24
|
+
Logger['client'].info "Bye Bye from client!"
|
25
|
+
Outputter['remote'].flush # flush the RemoteOutputter
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# How to use LogServer
|
2
|
+
|
3
|
+
$: << File.join('..','src')
|
4
|
+
require 'log4r'
|
5
|
+
require 'log4r/configurator'
|
6
|
+
|
7
|
+
# XML configuration is simple enough to embed here
|
8
|
+
xml = %(
|
9
|
+
<log4r_config>
|
10
|
+
<logserver name="server" uri="tcpromp://localhost:9999">
|
11
|
+
<outputter>stdout</outputter>
|
12
|
+
</logserver>
|
13
|
+
</log4r_config>
|
14
|
+
)
|
15
|
+
Log4r::Logger.new('log4r').add 'stdout' # to see what's going on inside
|
16
|
+
Log4r::Configurator.load_xml_string xml # load it up
|
17
|
+
sleep
|
18
|
+
# now run logclient.rb on another terminal
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<!-- the config file used by xmlconfig.rb -->
|
2
|
+
<log4r_config>
|
3
|
+
<pre_config>
|
4
|
+
<global level="DEBUG"/>
|
5
|
+
<!-- we'll set serverlog in XML and logpath at runtime for illustration -->
|
6
|
+
<parameter name="serverlog" value="./logs/server.log"/>
|
7
|
+
</pre_config>
|
8
|
+
|
9
|
+
<!-- outputters, illustrating XML config flexibility -->
|
10
|
+
<outputter type="FileOutputter" name="server">
|
11
|
+
<filename>#{serverlog}</filename>
|
12
|
+
<trunc>false</trunc>
|
13
|
+
</outputter>
|
14
|
+
<outputter type="FileOutputter" name="client"
|
15
|
+
filename="#{logpath}/client.log"/>
|
16
|
+
<outputter type="FileOutputter" name="gui"
|
17
|
+
filename="#{logpath}/guidebug.log"/>
|
18
|
+
<outputter type="StderrOutputter" name="console" level="ERROR"/>
|
19
|
+
|
20
|
+
<!-- loggers -->
|
21
|
+
|
22
|
+
<logger name="server" level="ERROR" outputters="server, console"/>
|
23
|
+
<logger name="client" level="INFO" outputters="client, console"/>
|
24
|
+
<logger name="client::gui" trace="true">
|
25
|
+
<level>DEBUG</level>
|
26
|
+
<outputter>gui</outputter>
|
27
|
+
</logger>
|
28
|
+
|
29
|
+
</log4r_config>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Now, for something more complicted
|
2
|
+
# Let's pretend this is the global config file for our app
|
3
|
+
|
4
|
+
$: << File.join('..','src')
|
5
|
+
require "log4r"
|
6
|
+
|
7
|
+
include Log4r # include Log4r to make things simple
|
8
|
+
|
9
|
+
Logger.root.level = DEBUG # global level DEBUG
|
10
|
+
|
11
|
+
# suppose we want to have loggers for a Server and a Client class
|
12
|
+
# furthermore, we want the client gui to have its own logger. (You'll want
|
13
|
+
# one logger per class or so.)
|
14
|
+
# When the loggers are created, they are stored in a repository for further
|
15
|
+
# retreival at any point using a hash method call: Logger['name']
|
16
|
+
|
17
|
+
# server is stable, so only log ERROR and FATAL
|
18
|
+
Logger.new("server", ERROR)
|
19
|
+
# let's say we don't need the DEBUG junk for client logs
|
20
|
+
Logger.new("client", INFO)
|
21
|
+
# but we're still debugging the gui
|
22
|
+
debugger = Logger.new("client::gui", DEBUG)
|
23
|
+
debugger.trace = true # we want to see where the log method was called
|
24
|
+
|
25
|
+
# Guilog is a child of client. In this case, any log events to the gui
|
26
|
+
# logger will also be logged to the client outputters. We can change
|
27
|
+
# that behavior by setting guilogger's 'additive' to false, but not yet.
|
28
|
+
|
29
|
+
# let's create the outputters
|
30
|
+
FileOutputter.new('server', :filename=>'logs/server.log', :trunc => false)
|
31
|
+
FileOutputter.new('client', :filename=>'logs/client.log')
|
32
|
+
FileOutputter.new('gui', :filename=>'logs/guidebug.log')
|
33
|
+
# additionally, we want ERROR and FATAL messages to go to stderr
|
34
|
+
StderrOutputter.new('console', :level=>ERROR)
|
35
|
+
|
36
|
+
# add the outputters
|
37
|
+
Logger['server'].add 'server', 'console'
|
38
|
+
Logger['client'].add 'client', 'console'
|
39
|
+
Logger['client::gui'].add 'gui' # gui will also write to client's outputters
|
40
|
+
|
41
|
+
# That's it for config. Now let's use the loggers:
|
42
|
+
|
43
|
+
def do_logging(log)
|
44
|
+
log.debug "debugging"
|
45
|
+
log.info "a piece of info"
|
46
|
+
log.warn "Danger, Will Robinson, danger!"
|
47
|
+
log.error "I dropped my Wookie! :("
|
48
|
+
log.fatal "kaboom!"
|
49
|
+
end
|
50
|
+
|
51
|
+
Logger.each_logger{|logger| do_logging(logger) }
|
52
|
+
|
53
|
+
# You can dynamically change levels and turn off tracing:
|
54
|
+
Logger['client'].level = OFF
|
55
|
+
Logger['client::gui'].trace = false
|
56
|
+
|
57
|
+
puts 'Only server should show Dynamic Change onscreen:'
|
58
|
+
Logger.each_logger{|logger| logger.fatal "Dynamic change." }
|
59
|
+
# logs/client.log file should not show "Dynamic change."
|
60
|
+
# logs/guidebug.log should not show the trace at "Dynamic change."
|
61
|
+
|
62
|
+
# we can also set our outputter to log only specified levels:
|
63
|
+
|
64
|
+
Outputter['console'].only_at ERROR
|
65
|
+
puts "Should only see ERROR next:"
|
66
|
+
do_logging Logger['server']
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# try out a custom formatter
|
2
|
+
|
3
|
+
$: << '../src'
|
4
|
+
|
5
|
+
require "log4r"
|
6
|
+
|
7
|
+
class MyFormatter < Log4r::Formatter
|
8
|
+
def format(event)
|
9
|
+
buff = "The level is #{event.level} and has "
|
10
|
+
buff += "name '#{Log4r::LNAMES[event.level]}'\n"
|
11
|
+
buff += "The logger is '#{event.name}' "
|
12
|
+
buff += "and the data type is #{event.data.class}\n"
|
13
|
+
buff += "Let's inspect the data:\n"
|
14
|
+
buff += event.data.inspect + "\n"
|
15
|
+
buff += "We were called at #{event.tracer[0]}\n\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
log = Log4r::Logger.new('custom formatter')
|
20
|
+
log.trace = true
|
21
|
+
log.add Log4r::StdoutOutputter.new('stdout', :formatter=>MyFormatter)
|
22
|
+
log.info [1, 2, 3, 4]
|
23
|
+
log.error "A log statement"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Here's how to start using log4r right away
|
2
|
+
$: << File.join('..','src') # path if log4r not installed
|
3
|
+
require "log4r"
|
4
|
+
|
5
|
+
Log = Log4r::Logger.new("outofthebox") # create a logger
|
6
|
+
Log.add Log4r::Outputter.stderr # which logs to stdout
|
7
|
+
|
8
|
+
# do some logging
|
9
|
+
def do_logging
|
10
|
+
Log.debug "debugging"
|
11
|
+
Log.info "a piece of info"
|
12
|
+
Log.warn "Danger, Will Robinson, danger!"
|
13
|
+
Log.error "I dropped my Wookie! :("
|
14
|
+
Log.fatal "kaboom!"
|
15
|
+
end
|
16
|
+
do_logging
|
17
|
+
|
18
|
+
# now let's filter anything below WARN level (DEBUG and INFO)
|
19
|
+
puts "-= Changing level to WARN =-"
|
20
|
+
Log.level = Log4r::WARN
|
21
|
+
do_logging
|
@@ -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>
|
data/examples/rrsetup.rb
ADDED
@@ -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('..','src')
|
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('..','src')
|
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,25 @@
|
|
1
|
+
# This is like moderateconfig.rb, but using an XML config
|
2
|
+
# please look at moderate.xml
|
3
|
+
|
4
|
+
$: << '../src'
|
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('..','src') # 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
|
+
include Log4r
|
10
|
+
|
11
|
+
cfg = 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
|
+
Outputter['email'].level = OFF
|
29
|
+
# the other two outputters log to stderr and a timestamped file in ./logs
|
30
|
+
do_logging( Logger['mylogger'])
|
data/src/log4r.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# :include: log4r/rdoc/log4r
|
2
|
+
#
|
3
|
+
# == Other Info
|
4
|
+
#
|
5
|
+
# Author:: Leon Torres
|
6
|
+
# Version:: $Id: log4r.rb,v 1.1.1.1 2004/03/19 03:31:06 fando Exp $
|
7
|
+
|
8
|
+
require "log4r/outputter/fileoutputter"
|
9
|
+
require "log4r/outputter/consoleoutputters"
|
10
|
+
require "log4r/outputter/staticoutputter"
|
11
|
+
require "log4r/outputter/rollingfileoutputter"
|
12
|
+
require "log4r/formatter/patternformatter"
|
13
|
+
require "log4r/loggerfactory"
|
14
|
+
|
15
|
+
module Log4r
|
16
|
+
Log4rVersion = [1, 0, 1].join '.'
|
17
|
+
end
|
data/src/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
|