mtn_log4r 1.1.11

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 (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,147 @@
1
+ <html>
2
+ <head>
3
+ <!-- TITLE -->
4
+ <link rel="stylesheet" type="text/css" href="log4r.css">
5
+ </head>
6
+ <body>
7
+
8
+ <div align="right"><img src="images/log4r-logo.png"/></div>
9
+ <hr noshade>
10
+
11
+ <table border="0" cellspacing="3" cellpadding="0" width="100%">
12
+ <tr>
13
+
14
+ <!-- Sidebar -->
15
+ <td width="15%" valign="top">
16
+ <table cellspacing="0" cellpadding="0" width=100%" nowrap="true">
17
+
18
+ <!-- Log4r Box -->
19
+ <tr><td >
20
+ <table width="100%" cellspacing="0" cellpadding="0" align="center" >
21
+ <tr><td width="100%" class="menutitle">Log4r</td></tr>
22
+ <tr><td width="100%" class="menubuff">&nbsp;</td></tr>
23
+ <!-- list -->
24
+ <table class="menu" cellspacing="3" cellpadding="0" width="100%"
25
+ align="center">
26
+ <tr><td ><a href="index.html">Home Page</a></tr></td>
27
+ <tr><td><a href="http://sourceforge.net/project/showfiles.php?group_id=43396">
28
+ Download</a></td></tr>
29
+ <tr><td nowrap="true">
30
+ <a href="http://rubyforge.org/projects/log4r/">@ RubyForge</a>
31
+ </td></tr>
32
+ <tr><td>
33
+ <a href="license.html">License</a>
34
+ </td></tr>
35
+ <tr><td>
36
+ <a href="contact.html">Contact</a>
37
+ </td></tr>
38
+ </table>
39
+ </td></tr>
40
+
41
+ <tr><td height=15>&nbsp;</td></tr>
42
+
43
+ <!-- Doc Box -->
44
+ <tr><td >
45
+ <table cellspacing="0" cellpadding="0" align="center" width="100%">
46
+ <tr><td width="100%" class="menutitle">Documents</td></tr>
47
+ <tr><td width="100%" class="menubuff">&nbsp;</td></tr>
48
+ <!-- list -->
49
+ <table class="menu" cellspacing="3" cellpadding="0" width="100%"
50
+ align="center">
51
+ <tr><td>
52
+ <a href="manual.html">#{version} Manual</a>
53
+ </tr></tr>
54
+ <tr><td>
55
+ <a href="rdoc/index.html">#{version} RDoc API</a>
56
+ </td></tr>
57
+
58
+ </table>
59
+ </td></tr>
60
+
61
+ <tr><td height=15>&nbsp;</td></tr>
62
+
63
+ <!-- Development Box -->
64
+ <tr><td >
65
+ <table cellspacing="0" cellpadding="0" align="center" width="100%">
66
+ <tr><td width="100%" class="menutitle">Development</td></tr>
67
+ <tr><td width="100%" class="menubuff">&nbsp;</td></tr>
68
+ <!-- list -->
69
+ <table class="menu" cellspacing="3" cellpadding="0" width="100%"
70
+ align="center">
71
+ <tr><td>
72
+ <a
73
+ href="http://sourceforge.net/tracker/?atid=436181&group_id=43396&func=browse">
74
+ Bugs</a>
75
+ </tr></tr>
76
+ <tr><td>
77
+ <a
78
+ href="http://sourceforge.net/tracker/?atid=436184&group_id=43396&func=browse">
79
+ Requests</a>
80
+ </td></tr>
81
+ <tr><td>
82
+ <a href="contribute.html">Contribute</a>
83
+ </td></tr>
84
+
85
+ </table>
86
+ </td></tr>
87
+
88
+ <tr><td height=15>&nbsp;</td></tr>
89
+
90
+
91
+ <!-- Link Box -->
92
+ <tr><td >
93
+ <table cellspacing="0" cellpadding="0" align="center" width="100%">
94
+ <tr><td width="100%" class="menutitle">Links</td></tr>
95
+ <tr><td width="100%" class="menubuff">&nbsp;</td></tr>
96
+ <!-- list -->
97
+ <table class="menu" cellspacing="3" cellpadding="0" width="100%"
98
+ align="center">
99
+ <tr><td>
100
+ <a href="http://www.ruby-lang.org/en/index.html">Ruby</a>
101
+ </td></tr>
102
+ <tr><td>
103
+ <a href="http://jakarta.apache.org/log4j/docs/index.html">Apache Log4j</a>
104
+ </tr></tr>
105
+ <tr><td>
106
+ <a href="http://www.ruby-lang.org/en/raa-list.rhtml?name=REXML">REXML</a>
107
+ </td></tr>
108
+ <tr><td>
109
+ <a href="http://rm-f.net/~cout/ruby/romp/">ROMP</a>
110
+ </td></tr>
111
+ <tr><td height="5">&nbsp;</td></tr>
112
+ <tr><td align="center">
113
+ <a href="http://rubyforge.org">
114
+ <!-- rubyforge image goes here -->
115
+ </a>
116
+ </a>
117
+ </td></tr>
118
+
119
+ </table>
120
+ </td></tr>
121
+
122
+ </table>
123
+ </td>
124
+
125
+ <!-- Main column -->
126
+ <td width="85%" align="left" valign="top">
127
+ <center>
128
+ <table cellspacing="0" cellpadding="0" align="center" width="95%">
129
+
130
+ <!-- CONTENT -->
131
+
132
+ </table>
133
+ </center>
134
+ </td>
135
+
136
+
137
+ </tr>
138
+ </table>
139
+ <hr noshade>
140
+ <div align="right">
141
+ <font color="#888888" size="-1">
142
+ <i>
143
+ <!-- CVSID -->
144
+ </i></font>
145
+ </div>
146
+ </body>
147
+ </html>
data/examples/README ADDED
@@ -0,0 +1,19 @@
1
+ The examples are:
2
+
3
+ 1. outofthebox.rb - How to get started with minimal setup
4
+ 2. simpleconfig.rb - Using Log4r casually
5
+ 3. moderateconfig.rb - A more sophisticated config
6
+ 4. xmlconfig.rb and moderate.xml - XML configuration example based on #3
7
+ 5. rrsetup.rb and rrconfig.xml - A real example (or used to be ;-)
8
+ 6. logserver.rb and logclient.rb - Remote logging example
9
+ 7. fileroll.rb - Using RollingFileOutputter
10
+ 8. yaml.rb and log4r_yaml.yaml - YAML configuration example
11
+
12
+ The output will go to screen and to files in the directory logs/.
13
+
14
+ Note to RubyGems users: The syntax to require log4r as a gem is as follows:
15
+
16
+ require 'rubygems'
17
+ require_gem 'log4r'
18
+
19
+ Obviously, the examples will need to be modified to follow this.
@@ -0,0 +1,53 @@
1
+ $: << File.join("..","lib")
2
+
3
+ # This file demonstrates how inheritence works in log4r
4
+ #
5
+ require 'rubygems'
6
+ require 'log4r'
7
+ include Log4r
8
+
9
+ Logger.global.level = ALL
10
+ formatter = PatternFormatter.new(:pattern => "%l - %m - %c")
11
+ StdoutOutputter.new('console', :formatter => formatter)
12
+
13
+
14
+ # By default, the root logger is the top ancestor to the
15
+ # immediate descendants
16
+ # However, any descendants below the top ancestors will
17
+ # have the ancestor as their RootLogger, which dictates
18
+ # (among other things) the lowest level of log messages
19
+ Logger.new('grandparent', FATAL).add('console')
20
+ Logger.new('grandparent::parent', DEBUG)
21
+ Logger.new('grandparent::parent::child', DEBUG)
22
+
23
+
24
+ def do_logging(log)
25
+ puts "--"
26
+ log.debug "This is debug"
27
+ log.info "This is info"
28
+ log.warn "This is warn"
29
+ log.error "This is error"
30
+ log.fatal "This is fatal"
31
+ end
32
+
33
+ # This logger is configured to log at FATAL, and it does
34
+ do_logging Logger['grandparent']
35
+
36
+ # This logger is configured to log at DEBUG level, but it logs
37
+ # at FATAL because grandparent is now the RootLogger for parent
38
+ do_logging Logger['grandparent::parent']
39
+
40
+ # 'child' logger is configured to log at DEBUG level, but it logs
41
+ # at FATAL because of grandparent
42
+ do_logging Logger['grandparent::parent::child']
43
+
44
+
45
+ Logger['grandparent'].level = DEBUG
46
+ # Now that the grandparent's level is set to DEBUG, the child
47
+ # will log at that level
48
+ do_logging Logger['grandparent::parent::child']
49
+
50
+ Logger['grandparent'].level = OFF
51
+ puts "off?"
52
+ do_logging Logger['grandparent::parent::child']
53
+
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3
+ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
4
+ <plugin name="log4r_test" class="org.apache.log4j.net.UDPReceiver">
5
+ <param name="Port" value="8071" />
6
+ </plugin>
7
+ </log4j:configuration>
@@ -0,0 +1,34 @@
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
+ # Log4r allows you to rename the levels and their corresponding methods
4
+ # in a painless way. This file provides and example
5
+
6
+ $: << '../lib'
7
+
8
+ require 'log4r'
9
+ require 'log4r/configurator'
10
+ include Log4r
11
+
12
+ # This is how we specify our levels
13
+ Configurator.custom_levels "Foo", "Bar", "Baz"
14
+
15
+ l = Logger.new('custom levels')
16
+ l.add StdoutOutputter.new('console')
17
+
18
+ l.level = Foo
19
+ puts l.foo?
20
+ l.foo "This is foo"
21
+ puts l.bar?
22
+ l.bar "this is bar"
23
+ puts l.baz?
24
+ l.baz "this is baz"
25
+
26
+ puts "Now change to Baz"
27
+
28
+ l.level = Baz
29
+ puts l.foo?
30
+ l.foo {"This is foo"}
31
+ puts l.bar?
32
+ l.bar {"this is bar"}
33
+ puts l.baz?
34
+ l.baz {"this is baz"}
@@ -0,0 +1,25 @@
1
+ # Here's how to start using log4r right away
2
+ $: << File.join('..','lib') # path if log4r not installed
3
+ require "log4r"
4
+
5
+ Log = Log4r::Logger.new("filelog") # create a logger
6
+ # add FileOutputter
7
+ Log.add Log4r::FileOutputter.new( "filelog", {:filename=>"file.log"} )
8
+
9
+ # See book keeping logger events
10
+ iLog = Log4r::Logger.new("log4r")
11
+ iLog.add Log4r::Outputter.stderr
12
+
13
+ # do some logging
14
+ def do_logging
15
+ Log.debug "debugging"
16
+ Log.info "a piece of info"
17
+ Log.warn "Danger, Will Robinson, danger!"
18
+ Log.error "I dropped my Wookie! :("
19
+ Log.fatal "kaboom!"
20
+ end
21
+ do_logging
22
+
23
+ # now let's filter anything below WARN level (DEBUG and INFO)
24
+ Log.level = Log4r::WARN
25
+ do_logging
@@ -0,0 +1,40 @@
1
+ # How to use RollingFileOutputter
2
+
3
+ $: << "../lib"
4
+ require 'log4r'
5
+ include Log4r
6
+
7
+ puts "this will take a while"
8
+
9
+ # example of log file being split by time constraint 'maxtime'
10
+ config = {
11
+ "filename" => "logs/TestTime.log",
12
+ "maxtime" => 10,
13
+ "trunc" => true
14
+ }
15
+ timeLog = Logger.new 'WbExplorer'
16
+ timeLog.outputters = RollingFileOutputter.new("WbExplorer", config)
17
+ timeLog.level = DEBUG
18
+
19
+ # log something once a second for 100 seconds
20
+ 100.times { |t|
21
+ timeLog.info "blah #{t}"
22
+ sleep(1.0)
23
+ }
24
+
25
+ # example of log file being split by space constraint 'maxsize'
26
+ config = {
27
+ "filename" => "logs/TestSize.log",
28
+ "maxsize" => 16000,
29
+ "trunc" => true
30
+ }
31
+ sizeLog = Logger.new 'WbExplorer'
32
+ sizeLog.outputters = RollingFileOutputter.new("WbExplorer", config)
33
+ sizeLog.level = DEBUG
34
+
35
+ # log a large number of times
36
+ 100000.times { |t|
37
+ sizeLog.info "blah #{t}"
38
+ }
39
+
40
+ puts "done! check the two sets of log files in logs/ (TestTime and TestSize)"
data/examples/gmail.rb ADDED
@@ -0,0 +1,30 @@
1
+ # Log4r can be configured using YAML to email using STARTTLS. This example uses gmail.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
+ 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('gmail.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 = WRN
29
+ # the other two outputters log to stderr and a timestamped file in ./logs
30
+ do_logging( Logger['mylogger'])
@@ -0,0 +1,95 @@
1
+
2
+
3
+ purpose : Test Mailing to Gmail
4
+ description: Provides configuration info for login to email servers via STARTTLS, e.g. gmail.com
5
+ say : gmail is nice
6
+
7
+ ---
8
+ # *** YAML2LOG4R ***
9
+ log4r_config:
10
+ # define all pre config ...
11
+ pre_config:
12
+ custom_levels:
13
+ - DEB
14
+ - INF
15
+ - PRT
16
+ - WRN
17
+ - ERR
18
+ - FAT
19
+ global:
20
+ level: DEB
21
+ root :
22
+ level: DEB
23
+ parameters:
24
+ - name : x
25
+ value : aaa
26
+ - name : y
27
+ value : bbb
28
+
29
+ # define all loggers ...
30
+ loggers:
31
+ - name : mylogger
32
+ level : DEB
33
+ additive : 'false'
34
+ trace : 'false'
35
+ outputters:
36
+ - stderr
37
+ - logfile
38
+ - email
39
+
40
+ - name : yourlogger
41
+ level : INF
42
+ outputters:
43
+ - stderr
44
+ - logfile
45
+
46
+ # define all outputters (incl. formatters)
47
+ outputters:
48
+ - type : StderrOutputter
49
+ name : stderr
50
+ level : DEB
51
+ only_at :
52
+ - INF
53
+ - WRN
54
+ - FAT
55
+ formatter:
56
+ date_pattern: '%y%m%d %H:%M:%S'
57
+ pattern : '%d %l: %m '
58
+ type : PatternFormatter
59
+
60
+ - type : DateFileOutputter
61
+ name : logfile
62
+ level : DEB
63
+ date_pattern: '%Y%m%d'
64
+ trunc : 'false'
65
+ dirname : "#{HOME}/logs"
66
+ formatter :
67
+ date_pattern: '%y%m%d %H:%M:%S'
68
+ pattern : '%d %l: %m'
69
+ type : PatternFormatter
70
+
71
+ - type : EmailOutputter
72
+ name : email
73
+ level : FAT
74
+ tls : 'true'
75
+ domain : gmail.com
76
+ server : smtp.gmail.com
77
+ port : '587'
78
+ subject : 'Message from testing:'
79
+ from : INSERT_YOUR_FROM_ADDRESS
80
+ to : INSERT_YOUR_TO_ADDRESS
81
+ acct : INSERT_YOUR_GMAIL_ACCOUNTNAME
82
+ passwd : INSERT_YOUR_GMAIL_PASSWORD
83
+ authtype : plain
84
+ immediate_at: FAT
85
+ formatfirst : 'true'
86
+ formatter :
87
+ date_pattern: '%y%m%d %H:%M:%S'
88
+ pattern : '%d %l: %m'
89
+ type : PatternFormatter
90
+
91
+ ---
92
+ purpose : TestB
93
+ description: This is the last YAML doc
94
+ say : Bye
95
+
Binary file
@@ -0,0 +1,25 @@
1
+ # How to use RemoteOutputter. See logserver.rb first.
2
+
3
+ $: << File.join('..','lib')
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('..','lib')
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('..','lib')
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
+ $: << '../lib'
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('..','lib') # 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
data/examples/rdoc-gen ADDED
@@ -0,0 +1,2 @@
1
+ rdoc --exclude *CVS* --exclude .*patch --exclude diff
2
+