File: manual.html

package info (click to toggle)
lua-logging 1.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 240 kB
  • ctags: 50
  • sloc: makefile: 20
file content (223 lines) | stat: -rw-r--r-- 7,790 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>LuaLogging: A simple API to use logging features in Lua</title>
    <link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
	
<div id="container">

<div id="product">
	<div id="product_logo"><a href="http://www.keplerproject.org">
		<img alt="LuaLogging logo" src="lualogging-128.png"/>
	</a></div>
	<div id="product_name"><big><strong>LuaLogging</strong></big></div>
	<div id="product_description">A simple API to use logging features in Lua</div>
</div> <!-- id="product" -->

<div id="main">
	
<div id="navigation">
<h1>LuaLogging</h1>
	<ul>
		<li><a href="index.html">Home</a>
			<ul>
				<li><a href="index.html#overview">Overview</a></li>
				<li><a href="index.html#status">Status</a></li>
				<li><a href="index.html#download">Download</a></li>
                <li><a href="index.html#dependencies">Dependencies</a></li>
				<li><a href="index.html#history">History</a></li>
				<li><a href="index.html#credits">Credits</a></li>
				<li><a href="index.html#contact">Contact</a></li>
			</ul>
		</li>
		<li><strong>Manual</strong>
			<ul>
				<li><a href="manual.html#introduction">Introduction</a></li>
				<li><a href="manual.html#installation">Installation</a></li>
				<li><a href="manual.html#logger">Logger objects</a></li>
				<li><a href="manual.html#examples">Examples</a></li>
			</ul>
		</li>
		<li><a href="manual.html#appenders">Appenders</a>
			<ul>
				<li><a href="console.html">Console</a></li>
				<li><a href="file.html">File</a></li>
				<li><a href="sql.html">SQL</a></li>
				<li><a href="socket.html">Socket</a></li>
				<li><a href="email.html">Email</a></li>
			</ul>
		</li>
        <li><a href="http://luaforge.net/projects/lualogging/">Project</a>
            <ul>
                <li><a href="http://luaforge.net/tracker/?group_id=51">Bug Tracker</a></li>
                <li><a href="http://luaforge.net/scm/?group_id=51">CVS</a></li>
            </ul>
        </li>
		<li><a href="license.html">License</a></li>
	</ul>
</div> <!-- id="navigation" -->

<div id="content">

<h2><a name="introduction"></a>Introduction</h2>

<p>LuaLogging provides a simple API to use logging features in Lua.
Its design was based on
<a href="http://logging.apache.org/log4j/docs/index.html">log4j</a>.
LuaLogging currently supports console, file, email, socket and sql
outputs through the use of <em><a href="#appenders">appenders</a></em>.</p>

<p>LuaLogging defines one single global variable, a table called
<code>logging</code> which holds a function to create new
<a href="#logger"><code>logger</code></a> objects.</p>

<p>This logger constructor receives a function
(known as the <em>appender</em> function)
that will be called on each call to log a message.</p>

<p>An <em>appender</em> function receives three arguments:</p>

<ul>
    <li><strong>self</strong>: the logger object</li>
    <li><strong>level</strong>: the logging level</li>
    <li><strong>message</strong>: the message to be logged</li>
</ul>

<h2><a name="installation"></a>Installation</h2>

<p>
LuaLogging follows the
<a href="http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf">package model</a>
for Lua 5.1, therefore it should be "installed" in you <code>package.path</code>
</p>

<h2><a name="logger"></a>Logger objects</h2>

<p>A logger object offers the following methods that writes log messages.</p>

<p>For each of the methods below, the parameter <code>message</code> may be any lua value,
not only strings. When necessary <code>message</code> is converted to a string.</p>

<p>The parameter <code>level</code> can be one of the variables enumerated below.
The values are presented in descending criticality, so if the minimum level is
defined as <code>logging.WARN</code> then <code>logging.INFO</code> and
<code>logging.DEBUG</code> levels messages are not logged.</p>

<dl class="reference">
    <dt><strong>logging.DEBUG</strong></dt>
    <dd>The <em>DEBUG</em> level designates fine-grained informational events that
    are most useful to debug an application.</dd>
    
    <dt><strong>logging.INFO</strong></dt>
    <dd>The <em>INFO</em> level designates informational messages that highlight the
    progress of the application at coarse-grained level.</dd>
    
    <dt><strong>logging.WARN</strong></dt>
    <dd>The <em>WARN</em> level designates potentially harmful situations.</dd>
    
    <dt><strong>logging.ERROR</strong></dt>
    <dd>The <em>ERROR</em> level designates error events that might still allow the
    application to continue running.</dd>
    
    <dt><strong>logging.FATAL</strong></dt>
    <dd>The <em>FATAL</em> level designates very severe error events that would
    presumably lead the application to abort.</dd>
</dl>

<h3>Methods</h3>

<dl class="reference">
    <dt><strong>logger:log (level, message)</strong></dt>
    <dd>Logs a message with the specified level.</dd>
    
    <dt><strong>logger:debug (message)</strong></dt>
    <dd>Logs a message with DEBUG level.</dd>
    
    <dt><strong>logger:info (message)</strong></dt>
    <dd>Logs a message with INFO level.</dd>
    
    <dt><strong>logger:warn (message)</strong></dt>
    <dd>Logs a message with WARN level.</dd>
    
    <dt><strong>logger:error (message)</strong></dt>
    <dd>Logs a message with ERROR level.</dd>
    
    <dt><strong>logger:fatal (message)</strong></dt>
    <dd>Logs a message with FATAL level.</dd>
    
    <dt><strong>logger:setLevel (level)</strong></dt>
    <dd>This method sets a minimum level for messages to be logged.</dd>
</dl>

<h2><a name="examples"></a>Examples</h2>

<p>The example below creates a logger that prints the level and message
to the standard output (or whatever the print function does).</p>

<pre class="example">
require "logging"

local logger = logging.new(function(self, level, message)
                             print(level, message)
                             return true
                           end)
                           
logger:setLevel (logging.WARN)
logger:log(logging.INFO, "sending email")

logger:info("trying to contact server")
logger:warn("server did not responded yet")
logger:error("server unreachable")
</pre>

<p>Upon execution of the above example the following lines will
show in the standard output. Notice that the <em>INFO</em> log requests
are not handled because the minimum level is set to <em>WARN</em>.</p>

<pre class="example">
WARN server did not responded yet
ERROR server unreachable
</pre>

<a name="appenders"></a> 

<h2>Appenders</h2>

The following appenders are included in the standard distribution. 

<ul>
<li><a href="console.html">Console</a></li>
<li><a href="file.html">File</a></li>
<li><a href="sql.html">SQL</a></li>
<li><a href="socket.html">Socket</a></li>
<li><a href="email.html">Email</a></li>
</ul>

<h2>Upgrading from 1.0.0</h2>

<p>Upgrading from LuaLogging 1.0.0 is very easy. The
<code>logger</code> object is fully compatible. You just need to
change the code that creates the object.</p>

<p>The <code>logger</code> constructor from 1.0.0 received a single
argument which was a filename. To upgrade to 1.1.0 you should
create a <code>logging.file</code> object instead, passing the
filename as argument. As simple as this.</p>

</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
	<p><small>$Id: manual.html,v 1.15 2007/10/30 19:57:59 carregal Exp $</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->

</body>
</html>