sml-log4r 1.0.6

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 (77) hide show
  1. data/doc/content/contact.html +22 -0
  2. data/doc/content/contribute.html +21 -0
  3. data/doc/content/index.html +90 -0
  4. data/doc/content/license.html +56 -0
  5. data/doc/content/manual.html +449 -0
  6. data/doc/dev/README.developers +40 -0
  7. data/doc/dev/checklist +14 -0
  8. data/doc/dev/things-to-do +2 -0
  9. data/doc/images/crush/logo2.png +0 -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/old/manual.html +348 -0
  14. data/doc/templates/main.html +147 -0
  15. data/examples/README +19 -0
  16. data/examples/customlevels.rb +34 -0
  17. data/examples/fileroll.rb +40 -0
  18. data/examples/log4r_yaml.yaml +0 -0
  19. data/examples/logclient.rb +25 -0
  20. data/examples/logserver.rb +18 -0
  21. data/examples/moderate.xml +29 -0
  22. data/examples/moderateconfig.rb +66 -0
  23. data/examples/myformatter.rb +23 -0
  24. data/examples/outofthebox.rb +21 -0
  25. data/examples/rrconfig.xml +63 -0
  26. data/examples/rrsetup.rb +42 -0
  27. data/examples/simpleconfig.rb +39 -0
  28. data/examples/xmlconfig.rb +25 -0
  29. data/examples/yaml.rb +30 -0
  30. data/src/log4r.rb +17 -0
  31. data/src/log4r/base.rb +74 -0
  32. data/src/log4r/config.rb +9 -0
  33. data/src/log4r/configurator.rb +224 -0
  34. data/src/log4r/formatter/formatter.rb +105 -0
  35. data/src/log4r/formatter/patternformatter.rb +108 -0
  36. data/src/log4r/lib/drbloader.rb +52 -0
  37. data/src/log4r/lib/xmlloader.rb +24 -0
  38. data/src/log4r/logevent.rb +28 -0
  39. data/src/log4r/logger.rb +194 -0
  40. data/src/log4r/loggerfactory.rb +89 -0
  41. data/src/log4r/logserver.rb +28 -0
  42. data/src/log4r/outputter/consoleoutputters.rb +18 -0
  43. data/src/log4r/outputter/datefileoutputter.rb +110 -0
  44. data/src/log4r/outputter/emailoutputter.rb +115 -0
  45. data/src/log4r/outputter/fileoutputter.rb +49 -0
  46. data/src/log4r/outputter/iooutputter.rb +55 -0
  47. data/src/log4r/outputter/outputter.rb +132 -0
  48. data/src/log4r/outputter/outputterfactory.rb +59 -0
  49. data/src/log4r/outputter/remoteoutputter.rb +40 -0
  50. data/src/log4r/outputter/rollingfileoutputter.rb +126 -0
  51. data/src/log4r/outputter/staticoutputter.rb +30 -0
  52. data/src/log4r/outputter/syslogoutputter.rb +75 -0
  53. data/src/log4r/rdoc/configurator +243 -0
  54. data/src/log4r/rdoc/emailoutputter +103 -0
  55. data/src/log4r/rdoc/formatter +39 -0
  56. data/src/log4r/rdoc/log4r +89 -0
  57. data/src/log4r/rdoc/logger +175 -0
  58. data/src/log4r/rdoc/logserver +85 -0
  59. data/src/log4r/rdoc/outputter +108 -0
  60. data/src/log4r/rdoc/patternformatter +128 -0
  61. data/src/log4r/rdoc/syslogoutputter +29 -0
  62. data/src/log4r/rdoc/yamlconfigurator +20 -0
  63. data/src/log4r/repository.rb +65 -0
  64. data/src/log4r/staticlogger.rb +49 -0
  65. data/src/log4r/yamlconfigurator.rb +0 -0
  66. data/tests/include.rb +7 -0
  67. data/tests/runtest.rb +6 -0
  68. data/tests/testbase.rb +45 -0
  69. data/tests/testcustom.rb +33 -0
  70. data/tests/testdefault.rb +25 -0
  71. data/tests/testformatter.rb +29 -0
  72. data/tests/testlogger.rb +198 -0
  73. data/tests/testoutputter.rb +112 -0
  74. data/tests/testpatternformatter.rb +26 -0
  75. data/tests/testxmlconf.rb +51 -0
  76. data/tests/xml/testconf.xml +37 -0
  77. metadata +140 -0
@@ -0,0 +1,22 @@
1
+ Title: Log4r - Contact
2
+ Template: main.html
3
+ Id: $Id: contact.html,v 1.3 2004/03/17 20:17:59 fando Exp $
4
+
5
+ <tr><td width="100%" class="contenttitle">Contact the Developers</td></tr>
6
+ <tr><td width="100%" class="contentbuff">&nbsp;</td></tr>
7
+ <tr><td width="100%" class="content">
8
+ Lead developer:
9
+ <p>
10
+ Leon Torres
11
+ &lt;leon(at)ugcs dot caltech dot edu</a>&gt;
12
+ <br/>
13
+ Pasadena, CA, USA (UTC-8)
14
+ <p/>
15
+ Contributors:
16
+ <ul>
17
+ <li>Martain Stannard - for RollingFileOutputter and for caring about maintenance
18
+ <li>Steve Lumos - for SyslogOutputter
19
+ <li>Jamis Buck - for making Log4r available as a RubyGems gem
20
+ <li>Andreas Hund - for YAML configuration with YamlConfigurator
21
+ </ul>
22
+ </td></tr>
@@ -0,0 +1,21 @@
1
+ Title: Log4r - Contribute
2
+ Template: main.html
3
+ Id: $Id: contribute.html,v 1.5 2004/03/17 20:17:59 fando Exp $
4
+
5
+ <tr><td width="100%" class="contenttitle">Contributing to Log4r</td></tr>
6
+ <tr><td width="100%" class="contentbuff">&nbsp;</td></tr>
7
+ <tr><td width="100%" class="content">
8
+ If you wish to contribute something to Log4r or assist in development,
9
+ please drop an email to Leon: leon(at)ugcs dot caltech dot edu</a>. There
10
+ will always be work to do. Some things that come to mind are:
11
+ <p/>
12
+
13
+ <font size="-1">
14
+ <ul>
15
+ <li> Find bugs and flaws, or areas to improve
16
+ <li> More Outputters that do various nifty things
17
+ <li> More and better documentation
18
+ <li> And, of course, spreading the good word <code>;-)</code>
19
+ </ul>
20
+ </font>
21
+ </td></tr>
@@ -0,0 +1,90 @@
1
+ Title: Log4r - Manual
2
+ Template: main.html
3
+ Id: $Id: index.html,v 1.8 2004/03/18 03:58:57 fando Exp $
4
+
5
+ <tr><td width="100%" class="contenttitle">A Powerful Logging Library for Ruby
6
+ </td></tr>
7
+ <tr><td width="100%" class="contentbuff">&nbsp;</td></tr>
8
+ <tr><td width="100%" class="content">
9
+
10
+ <h4 class="header">What Log4r Is</h4>
11
+ Log4r is a comprehensive and flexible logging library written in Ruby
12
+ for use in Ruby programs. It features a hierarchical logging system
13
+ of any number of levels, custom level names, logger inheritance,
14
+ multiple output destinations, execution tracing, custom formatting, thread
15
+ safteyness, XML and YAML configuration, and more.
16
+ <p/>
17
+ Log4r is an adherent to the philosophy of logging using simple print
18
+ statements. What Log4r adds to this philosophy is a flexible way of
19
+ controling the information being logged. Log information can be sent to
20
+ any kind of destination and with varying degrees of importance. Log4r is
21
+ designed so that logging statements can remain in production code with
22
+ almost no extra computational cost.
23
+ <p/>
24
+ Log4r intends to be easy to use and configure, no matter the complexity.
25
+ Casual scripts can use Log4r right away with minimal configuration, while
26
+ more sophisticated applications can set up a structured configuration file
27
+ in XML or YAML. Comprehensive documentation is provided, with a user's manual,
28
+ a reference API, and over a dozen examples. Log4r attempts to abide by the
29
+ Principle of Least Surprise, which means that it works as intended at all
30
+ points.
31
+ <p/>
32
+ Log4r was inspired by and provides much of the features of the
33
+ <a href="http://jakarta.apache.org/log4j/docs/index.html">Apache Log4j</a>
34
+ project, but is not a direct implementation or clone. Aside from superficial
35
+ similarities, the projects are not related in any way and the code base is
36
+ completely distinct. Log4r was developed without even looking at the
37
+ Apache Log4j code.
38
+ <p/>
39
+ Log4r is an Open Source project and intends to remain that way. The Log4r
40
+ license is similar to the Ruby Language license. It resides on
41
+ <a href="license.html">this page</a> and in the distribution in a file
42
+ named LICENSE.
43
+
44
+ <!--
45
+ <p><hr noshade color="#AA0000">
46
+ <h4 class="header">But Why?</h4>
47
+
48
+ Why a logging system like Log4r?
49
+ <p/>
50
+
51
+ There are many non-obvious reasons. First,
52
+ logging should not be confused with Unit testing. Unit testing and logging are
53
+ complementary rather than exclusive. Second, logging provides a handy way
54
+ for a program to provide useful information about itself to different
55
+ audiences. With logging, your application's state can be tracked over time and
56
+ not be a complete mystery. With Log4r, you can control the amount and type of
57
+ information that show up without having to comment out the logging statements
58
+ in your code. This helps reduce noise and maximize the usefulness of log files.
59
+ Finally, logging is extremely useful in applications that are not all in one
60
+ place (distributed). If you want to debug a client and server at the same time,
61
+ a logging system like Log4r becomes critical.
62
+ -->
63
+
64
+ <p><hr noshade color="#AA0000">
65
+ <h4 class="header">Getting Started with Log4r</h4>
66
+
67
+ <ol>
68
+ <li> Download the latest version from
69
+ <a href="http://sourceforge.net/project/showfiles.php?group_id=43396">this page</a>
70
+ <li> Try out the examples in the <tt>examples</tt> directory of the distribution
71
+ <li> Install by running <tt>ruby install.rb</tt>
72
+ <li> Read the nice <a href="manual.html">manual</a>
73
+ <li> Use Log4r
74
+ <li> Consult the <a href="rdoc/index.html">Log4r RDoc API</a> for reference
75
+ <li> <a href="http://www.ruby-lang.org/en/raa-list.rhtml?name=REXML">
76
+ Get REXML</a> to take advantage of the XML config
77
+ <li> <a href="contribute.html">Contribute</a>!
78
+ </ol>
79
+
80
+ <h4 class="header">Install Using RubyGems</h4>
81
+
82
+ <p>
83
+ If you have <a href="http://rubygems.rubyforge.org/wiki/wiki.pl?RubyGems">RubyGems</a>, install the Log4r gem!
84
+
85
+ <ul>
86
+ <li> gem --remote-install log4r
87
+ </ul>
88
+ </p>
89
+
90
+ </td></tr>
@@ -0,0 +1,56 @@
1
+ Title: Log4r License
2
+ Template: main.html
3
+ Id: $Id: license.html,v 1.1 2002/01/16 09:56:00 cepheus Exp $
4
+
5
+ <tr><td width="100%" class="contenttitle">Log4r License</td></tr>
6
+ <tr><td width="100%" class="contentbuff">&nbsp;</td></tr>
7
+ <tr><td width="100%" class="content">
8
+ <pre>
9
+ Log4r is copyrighted free software by Leon Torres &lt;leon@ugcs.caltech.edu&gt;.
10
+ You can redistribute it and/or modify it under either the terms of the GPL,
11
+ or the conditions below:
12
+
13
+ 1. You may make and give away verbatim copies of the source form of the
14
+ software without restriction, provided that you duplicate all of the
15
+ original copyright notices and associated disclaimers.
16
+
17
+ 2. You may modify your copy of the software in any way, provided that
18
+ you do at least ONE of the following:
19
+
20
+ a) place your modifications in the Public Domain or otherwise
21
+ make them Freely Available, such as by posting said
22
+ modifications to Usenet or an equivalent medium, or by allowing
23
+ the author to include your modifications in the software.
24
+
25
+ b) use the modified software only within your corporation or
26
+ organization.
27
+
28
+ c) rename any non-standard executables so the names do not conflict
29
+ with standard executables, which must also be provided.
30
+
31
+ d) make other distribution arrangements with the author.
32
+
33
+ 3. You may distribute the software in object code or executable
34
+ form, provided that you do at least ONE of the following:
35
+
36
+ a) distribute the executables and library files of the software,
37
+ together with instructions (in the manual page or equivalent)
38
+ on where to get the original distribution.
39
+
40
+ b) accompany the distribution with the machine-readable source of
41
+ the software.
42
+
43
+ c) give non-standard executables non-standard names, with
44
+ instructions on where to get the original software distribution.
45
+
46
+ d) make other distribution arrangements with the author.
47
+
48
+ 4. You may modify and include the part of the software into any other
49
+ software (possibly commercial).
50
+
51
+ 5. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
52
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
53
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54
+ PURPOSE.
55
+ </pre>
56
+ </td></tr>
@@ -0,0 +1,449 @@
1
+ Title: #{version} Log4r Manual
2
+ Template: main.html
3
+ Id: $Id: manual.html,v 1.15 2004/03/18 03:58:58 fando Exp $
4
+
5
+ <tr><td width="100%" class="contenttitle">#{version} Log4r Manual</td></tr>
6
+ <tr><td width="100%" class="contentbuff">&nbsp;</td></tr>
7
+ <tr><td width="100%" class="content">
8
+
9
+ <a name="toc">
10
+ <h4 ><a href="#toc">Table of Contents</a></h4>
11
+
12
+ <ul>
13
+ <li><a href="#scope">Scope of This Manual</a>
14
+ <li><a href="#is">What Log4r Is</a>
15
+ <li><a href="#outofbox">Out of the Box</a>
16
+ <li><a href="#overview">Overview</a>
17
+ <ul>
18
+ <li><a href="#levels"> Levels</a>
19
+ <li><a href="#loggers"> Loggers</a>
20
+ <li><a href="#outputters"> Outputters</a>
21
+ <li><a href="#formatters"> Formatters</a>
22
+ <li><a href="#config"> Configuration</a>
23
+ <li><a href="#remote"> Remote Logging</a>
24
+ </ul>
25
+ <li><a href="#art">The Art of Logging</a>
26
+ <ul>
27
+ <li><a href="#avoid">Avoiding Parameter Evaluation</a>
28
+ <li><a href="#howmany">How Many?</a>
29
+ <li><a href="#whereto">Where To?</a>
30
+ <li><a href="#tracing">Where From?</a>
31
+ <li><a href="#who">Who's Talking?</a>
32
+ <li><a href="#nullobj">The Null Logger</a>
33
+ </ul>
34
+ <li><a href="#gotchas">Gotchas</a>
35
+ <li><a href="#performance">Performance</a>
36
+ <li><a href="#project">The Project Itself</a>
37
+ </ul>
38
+
39
+ <hr noshade color="#AA0000">
40
+
41
+ <a name="scope">
42
+ <h4 ><a href="#toc">Scope of this Manual</a></h4>
43
+
44
+ Most of the API documentation resides in the
45
+ <a href="rdoc/index.html">Log4r RDoc API</a>, so this manual will be brief
46
+ and targeted to people starting to learn about Log4r or who want to see
47
+ what Log4r has to offer.
48
+ <p/>
49
+ Besides the general overview, a section called
50
+ <a href="#art">The Art of Logging</a> provides tricks and tips in using
51
+ Log4r efficiently.
52
+ <p/>
53
+ Click on the section title to go back to the
54
+ <a href="#toc">Table of Contents</a> at any time.
55
+
56
+ <p/><hr noshade color="#AA0000">
57
+ <a name="is">
58
+ <h4 ><a href="#toc">What Log4r Is</a></h4>
59
+ Log4r is a comprehensive and flexible logging library written in Ruby
60
+ for use in Ruby programs. It features a hierarchical logging system
61
+ of any number of levels, custom level names, logger inheritance,
62
+ multiple output destinations, execution tracing, custom formatting, thread
63
+ safteyness, XML and YAML configuration, and more.
64
+ <p/>
65
+ Log4r is an adherent to the philosophy of logging using simple print
66
+ statements. What Log4r adds to this philosophy is a flexible way of
67
+ controling the information being logged. Log information can be sent to
68
+ any kind of destination and with varying degrees of importance. Log4r is
69
+ designed so that logging statements can remain in production code with
70
+ almost no extra computational cost.
71
+ <p/>
72
+ Log4r intends to be easy to use and configure, no matter the complexity.
73
+ Casual scripts can use Log4r right away with minimal configuration, while
74
+ more sophisticated applications can set up a structured configuration file
75
+ in XML or YAML. Comprehensive documentation is provided, with a user's manual,
76
+ a reference API, and over a dozen examples. Log4r attempts to abide by the
77
+ Principle of Least Surprise, which means that it works as intended at all
78
+ points.
79
+ <p/>
80
+ Log4r was inspired by and provides much of the features of the
81
+ <a href="http://jakarta.apache.org/log4j/docs/index.html">Apache Log4j</a>
82
+ project, but is not a direct implementation or clone. Aside from superficial
83
+ similarities, the projects are not related in any way and the code base is
84
+ completely distinct. Log4r was developed without even looking at the
85
+ Apache Log4j code.
86
+ <p/>
87
+ Log4r is an Open Source project and intends to remain that way. The Log4r
88
+ license is similar to the Ruby Language license. It resides on
89
+ <p/>
90
+ While Log4r is interpreted, it attempts to achieve optimal performance and
91
+ scale well. Already, plans are being made to write the performance-critical
92
+ components as a C extension to Ruby.
93
+ <p/>
94
+ Log4r was inspired by and provides much of the features of the
95
+ <a href="http://jakarta.apache.org/log4j/docs/index.html">Apache Log4j</a>
96
+ project, but is not a direct implementation or clone. Aside from superficial
97
+ similarities, the projects are not related in any way and the code base is
98
+ completely distinct. Log4r was developed without even looking at the
99
+ Apache Log4j code.
100
+ <p/>
101
+ Log4r is an Open Source project and intends to remain that way. The Log4r
102
+ license is similar to the Ruby Language license. It resides on
103
+ <a href="license.html">this page</a> and in the distribution in a file
104
+
105
+ <p><hr noshade color="#AA0000">
106
+ <a name="outofbox">
107
+ <h4 ><a href="#toc">Out of the Box</a></h4>
108
+
109
+ Here's an example of how to use Log4r right away.
110
+ <div class="example">
111
+ <pre class="box">require 'log4r'
112
+ include Log4r
113
+
114
+ # create a logger named 'mylog' that logs to stdout
115
+ mylog = Logger.new 'mylog'
116
+ mylog.outputters = Outputter.stdout
117
+
118
+ # Now we can log.
119
+ def do_log(log)
120
+ log.debug "This is a message with level DEBUG"
121
+ log.info "This is a message with level INFO"
122
+ log.warn "This is a message with level WARN"
123
+ log.error "This is a message with level ERROR"
124
+ log.fatal "This is a message with level FATAL"
125
+ end
126
+ do_log(mylog)
127
+ </pre>
128
+ </div>
129
+
130
+ The output will look something like this:
131
+
132
+ <div class="example">
133
+ <pre class="box">DEBUG mylog: This is a message with level DEBUG
134
+ INFO mylog: This is a message with level INFO
135
+ WARN mylog: This is a message with level WARN
136
+ ERROR mylog: This is a message with level ERROR
137
+ FATAL mylog: This is a message with level FATAL</pre>
138
+ </div>
139
+
140
+ For ease of access, the logger is stored in a hashtable keyed to its name:
141
+
142
+ <div class="example">
143
+ <pre class="box">mylog = Logger['mylog'] # Get our logger back</pre>
144
+ </div>
145
+
146
+ Suppose we want to turn off <tt>DEBUG</tt>, <tt>INFO</tt>
147
+ and <tt>WARN</tt> messages and see only <tt>ERROR</tt> and <tt>FATAL</tt>.
148
+ To do this, we set the level threshold for mylog to <tt>ERROR</tt>:
149
+
150
+ <div class="example">
151
+ <pre class="box">mylog.level = ERROR</pre>
152
+ </div>
153
+
154
+ Running <tt>do_log(mylog)</tt> yields:
155
+
156
+ <div class="example">
157
+ <pre class="box">ERROR mylog: This is a message with level ERROR
158
+ FATAL mylog: This is a message with level FATAL</pre>
159
+ </div>
160
+
161
+ <p><hr noshade color="#AA0000">
162
+ <a name="overview">
163
+ <h4 ><a href="#toc">Overview</a></h4>
164
+
165
+ We will now go over the components of Log4r. A summary of each is provided,
166
+ and links to the
167
+ <a href="rdoc/index.html">Log4r RDoc API</a> are provided for further perusal.
168
+
169
+ <p><hr noshade color="#AA0000">
170
+ <a name="levels">
171
+ <h4 ><a href="#toc">Levels</a></h4>
172
+
173
+ Log4r uses a hierarchical system of logging. That is, certain log events
174
+ can have a higher priority than other log events. Hence, one can control
175
+ how much information one wants to log by adjusting the <b>level threshold</b>
176
+ of logging. By default, the logging levels and priorities are:
177
+
178
+ <div class="example">
179
+ <pre class="box">DEBUG &lt; INFO &lt; WARN &lt; ERROR &lt; FATAL</pre>
180
+ </div>
181
+ In the previous section, we saw how setting the level to <tt>ERROR</tt>
182
+ prevented messages with levels <tt>DEBUG</tt>, <tt>INFO</tt> and <tt>WARN</tt>
183
+ from showing up. The names and numbers of these levels are configurable.
184
+ You can have any number of levels and name them whatever you wish. The
185
+ logging methods we saw in the last section will be named after the custom
186
+ levels. Log4r adjusts itself to suit your needs.
187
+ <p/>
188
+
189
+ To find out more about levels, please see
190
+ <a href="rdoc/files/log4r_rb.html">rdoc/files/log4r_rb.html</a>.
191
+
192
+ <p><hr noshade color="#AA0000">
193
+ <a name="loggers">
194
+ <h4 ><a href="#toc">Loggers</a></h4>
195
+ The principle interface in Log4r is a Logger. Loggers have one logging method
196
+ for each level and any number of output destinations. A logger's level
197
+ threshold and output destinations may be changed dynamically. Loggers are
198
+ stored within a Repository for retrieval at any time. Loggers provide
199
+ all kinds of data for logging: the log message itself, the line number and
200
+ file it was called in, a timestamp, the log priority, and so on.
201
+ <p/>
202
+ Loggers can inherit other Loggers. Inheritance means that a Logger initially
203
+ adopts the characteristics of its parent if none are specified. A Logger's
204
+ level is inherited once, and a Logger will write to its parents output
205
+ destinations as well as its own. This behavior is optional, but allows one
206
+ to structure a powerful, and easily configurable logging system.
207
+ <p/>
208
+ To find out more about loggers, please see
209
+ <a href="rdoc/files/log4r/logger_rb.html">rdoc/files/log4r/logger_rb.html</a>.
210
+ <p><hr noshade color="#AA0000">
211
+ <a name="outputters">
212
+ <h4 ><a href="#toc">Outputters</a></h4>
213
+
214
+ An output destination (file, raw IO, stdout, etc.) is represented by an
215
+ Outputter object. An Outputter has a
216
+ particular means of formatting data (Formatter) and has a level threshold
217
+ of its own. Outputters, like Loggers, are stored in a repository and can be
218
+ retrieved and manipulated at any time. Every outputter is thread-safe, meaning
219
+ that multiple threads can log to the same Outputter without worrying about
220
+ race conditions.
221
+ <p/>
222
+ There is a growing collection of outputters provided: raw IO, to stdout,
223
+ to stderr, to files (including one that splits and zips up logs periodically),
224
+ to syslog and to an email address. If a specialized Outputter is needed, one
225
+ can be created from scratch in almost no time, thanks to the ease of
226
+ extending log4r outputters, the well documented code and the open source
227
+ license.
228
+ <p/>
229
+ To find out more about outputters, please see
230
+ <a href="rdoc/files/log4r/outputter/outputter_rb.html">
231
+ rdoc/files/log4r/outputter/outputter_rb.html</a>.
232
+ <p><hr noshade color="#AA0000">
233
+ <a name="formatters">
234
+ <h4 ><a href="#toc">Formatters</a></h4>
235
+ A Formatter is responsible for rendering a log message into an output format.
236
+ Several Formatters are provided, including the powerful PatternFormatter.
237
+ PatternFormatter uses sprintf-like directives to format log messages and
238
+ eliminates the need for custom Formatters.
239
+ <p/>
240
+ To find out more about formatters, please see
241
+ <a href="rdoc/files/log4r/formatter/formatter_rb.html">
242
+ rdoc/files/log4r/formatter/formatter_rb.html</a>.
243
+ <br/>
244
+ To find out more about PatternFormatter, please see
245
+ <a href="rdoc/files/log4r/formatter/patternformatter_rb.html">
246
+ rdoc/files/log4r/formatter/patternformatter_rb.html</a>.
247
+ <p><hr noshade color="#AA0000">
248
+ <a name="config">
249
+ <h4 ><a href="#toc">Configuration</a></h4>
250
+ Configuring Log4r is accomplished via the Configurator and YamlConfigurator
251
+ classes. They allow one to set custom levels and load up XML or YAML
252
+ configurations. The XML and YAML grammar used by Log4r is extremely flexible
253
+ and can accomodate the configuration of custom Outputters and Formatters with
254
+ no extra work. That is, if a custom Outputter is created, it can immedieately
255
+ be configured without needing to write extra code. This is acomplished by
256
+ taking advantage of Ruby's powerful reflection capabilities.
257
+ <p/>
258
+ To find out more about configuration, please see
259
+ <a href="rdoc/files/log4r/configurator_rb.html">rdoc/files/log4r/configurator_rb.html</a>.
260
+ <br/>
261
+ For YAML configuration, also see
262
+ <a href="rdoc/files/log4r/yamlconfigurator_rb.html">rdoc/files/log4r/yamlconfigurator.html</a>
263
+
264
+ <p><hr noshade color="#AA0000">
265
+ <a name="remote">
266
+ <h4 ><a href="#toc">Remote Logging</a></h4>
267
+
268
+ It is possible to send log events from an Outputter to a Logger over a network.
269
+ This is accomplished using the distributed Ruby library ROMP, a subclass of
270
+ Logger called LogServer, and a RemoteOutputter.
271
+ <p/>
272
+ To find out more about remote logging, please see
273
+ <a href="rdoc/files/log4r/logserver_rb.html">
274
+ rdoc/files/log4r/logserver_rb.html</a>
275
+ <p/>
276
+ Alternatively, one can just send log reports via email using EmailOutputter.
277
+ <p/>
278
+ To find out more about EmailOutputter, please see
279
+ <a href="rdoc/classes/Log4r/EmailOutputter.html">
280
+ rdoc/classes/Log4r/EmailOutputter.html</a>
281
+
282
+ <p><hr noshade color="#AA0000">
283
+ <a name="art">
284
+ <h4 ><a href="#toc">The Art of Logging</a></h4>
285
+
286
+ Log4r in itself does not automatically enable people to understand logging,
287
+ however it does provide tools to assist in <i>The Art of Logging</i>. We will
288
+ now cover some of the techniques in this art and how to use Log4r to
289
+ accomplish them.
290
+
291
+ <p><hr noshade color="#AA0000">
292
+ <a name="avoid">
293
+ <h4 ><a href="#toc">Avoiding Parameter Evaluation</a></h4>
294
+
295
+ Suppose we have a complex structure and don't have the time to
296
+ make a special <tt>to_s</tt> method. When we want to log the contents
297
+ of the object, we end up doing something like this:
298
+
299
+ <div class="example">
300
+ <pre class="box">log.debug( myobj.collect{|e| e.collect{|p| p.to_s}} )</pre>
301
+ </div>
302
+
303
+ It is expensive to do this because every time the debug method is called,
304
+ the parameters passed to it will be evaluated. Because this is a feature of
305
+ Ruby, setting the logger to <tt>OFF</tt> will not prevent the evaluation.
306
+ There are two ways to get around parameter evaluation. The first is to
307
+ perform a simple if condition:
308
+
309
+ <div class="example">
310
+ <pre class="box">if log.debug?
311
+ log.debug( myobj.collect{|e| e.collect{|p| p.to_s}} )
312
+ end</pre></div>
313
+ </div>
314
+
315
+ Here we are introduced to <tt>log.debug?</tt>, which is called a
316
+ <i>query method</i>. It returns true if <tt>DEBUG</tt> messages are being
317
+ logged, otherwise it returns false. Query methods are very cheap
318
+ to invoke and are a great way to encapsulate complext logging statements.
319
+ The query methods, like the logging ones, are named after the levels, but with
320
+ a question mark at the end. As another example, <tt>log.info?</tt> will find
321
+ out if <tt>INFO</tt> is being logged and so on.
322
+ <p/>
323
+ The second way around parameter evaluation is to pass a block to the
324
+ logging method:
325
+
326
+ <div class="example">
327
+ <pre class="box">log.debug { myobj.collect{|e| e.collect{|p| p.to_s} }</pre>
328
+ </div>
329
+
330
+ The block will be evaluated if and only if the logger is capable of handling
331
+ <tt>DEBUG</tt> log events.
332
+
333
+ <p><hr noshade color="#AA0000">
334
+ <a name="howmany">
335
+ <h4 ><a href="#toc">How Many?</a></h4>
336
+ How many loggers should one have? Only experience can tell, but
337
+ a general rule of thumb is to create one static logger per class and
338
+ one per service or state.
339
+ <p/>
340
+ When dealing with a large number of loggers, logger
341
+ inheritance and additivity can help organize what gets logged and to where.
342
+ <p/>
343
+ The configuration possibilities in Log4r are uncountable and can sometimes
344
+ be daunting. It's best to start with something simple and evolve it over time.
345
+ To assist in this task, Log4r can be set up using XML or YAML configuration
346
+ files.
347
+ <p><hr noshade color="#AA0000">
348
+ <a name="whereto">
349
+ <h4 ><a href="#toc">Where To?</a></h4>
350
+ Log4r lets one associate any number of Outputters to a Logger. Logger
351
+ additivity enables propagation of a log event upwards in the logger hierarchy.
352
+ The outputters themselves can have their own level thresholds. Unlike normal
353
+ loggers, Outputters can log at certain specific log levels. this allows
354
+ one to channel particular data to a particular output. All things considered,
355
+ log4r offers tremendous flexibility in deciding what gets logged where.
356
+
357
+ <p><hr noshade color="#AA0000">
358
+ <a name="tracing">
359
+ <h4 ><a href="#toc">Where From?</a></h4>
360
+
361
+ Want to find out where a particular log statement came from? Loggers have
362
+ tracers which record the call stack when turned on:
363
+
364
+ <div class="example">
365
+ <pre class="box">Logger['mylog'].trace = true</pre>
366
+ </div>
367
+
368
+ The trace is then accesible by a Formatter.
369
+
370
+ <p><hr noshade color="#AA0000">
371
+ <a name="who">
372
+ <h4 ><a href="#toc">Who's Talking?</a></h4>
373
+
374
+ If there are many loggers that use logger inheritance,
375
+ it's occasionally a good idea to show the full ancestry of a logger in the log
376
+ statement. Here's how to set up PatternFormatter to show the full ancestry
377
+ of a logger in a logging statement (in XML):
378
+
379
+ <div class="example">
380
+ <pre class="box">&lt;formatter type="PatternFormatter"&gt;
381
+ &lt;!-- %C shows full ancestry --&gt;
382
+ &lt;pattern&gt;[%l %C] %m&lt;/pattern&gt;
383
+ &lt;/formatter&gt;</pre>
384
+ </div>
385
+
386
+ For a logger named 'me' with ancestors 'cain::grandpa::pa', it will produce:
387
+
388
+ <div class="example">
389
+ <pre class="box">[DEBUG cain::grandpa::pa::me] Log message</pre>
390
+ </div>
391
+
392
+ <p><hr noshade color="#AA0000">
393
+ <a name="nullobj">
394
+ <h4 ><a href="#toc">The Null Logger</a></h4>
395
+ In addition to being the parent of all loggers, Logger.root is a null
396
+ object. That means that it does absolutely nothing when its log methods are
397
+ invoked. Its query methods always return false and it has no outputters.
398
+ It is useful to turn loggers off from within code:
399
+
400
+ <div class="example">
401
+ <pre class="box">noisylog = Logger.root
402
+ noisy.debug "This won't do anything"</pre>
403
+ </div>
404
+
405
+ <p><hr noshade color="#AA0000">
406
+ <a name="gotchas">
407
+ <h4 ><a href="#toc">Gotchas</a></h4>
408
+
409
+ If you are using Log4r, there are a few gotchas that you should be aware of:
410
+
411
+ <ul>
412
+ <li>Logger levels can be dynamically redefined, but the change won't be
413
+ noticed by any children. That is, if you set <code>root.level=OFF</code>
414
+ <i>after</i> defining some loggers, none of the loggers will change their level
415
+ to <code>OFF</code>. There is a good reason for this behavior.
416
+ </li>
417
+ <li>Dynamically redefining levels, tracing or additivity is expensive. It's
418
+ best to set up all your loggers in a config script and avoid making dynamic
419
+ changes to Log4r objects. The dynamism is most useful for debugging and
420
+ development, where local control of logging is a great convenience.
421
+ </li>
422
+ <li>When an <code>IOOutputter</code>'s <code>IO</code> is closed,
423
+ the <code>IOOutputter</code> changes its level to <code>OFF</code>
424
+ </li>
425
+ </ul>
426
+
427
+ <p><hr noshade color="#AA0000">
428
+ <a name="performance">
429
+ <h4 ><a href="#toc">Performance</a></h4>
430
+
431
+ Profiling has revealed that log4r is typically an order of magnitude or
432
+ two slower than log4j. However, this is still damn fast! In particular,
433
+ if a logger is set to <code>OFF</code>, the overhead of checking to
434
+ see if a log event should be logged nearly vanishes. This was accomplished by
435
+ dynamically redefining the unloggable logging methods to do nothing.
436
+ <p/>
437
+ In the future, Log4r's performance critical features will be written as a C
438
+ extension to Ruby. It will still be optional, but it will be available for
439
+ those who absolutely need to squeeze every last ounce of performance out of
440
+ Log4r. (No longer in the works, unfortunately.)
441
+ <p><hr noshade color="#AA0000">
442
+ <a name="project">
443
+ <h4 ><a href="#toc">The Project Itself</a></h4>
444
+ Log4r was initially developed by one person and is slowly but surely gaining
445
+ popularity and new developers. Please refer to the
446
+ <a href="contact.html">contact</a> page for more information on the
447
+ developers.
448
+
449
+ </td></tr>