-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
105 lines (84 loc) · 2.82 KB
/
index.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/transitional.dtd">
<html>
<head>
<title>lsyslog: a Lua wrapper for the syslog C API</title>
</head>
<body>
<h3>What is it</h3>
lsyslog is a Lua module that wraps the
<a href="http://www.die.net/doc/linux/man/man3/syslog.3.html">syslog(3)</a> C API.
It has been tested with Lua 5.1 on Linux.
<h3>Download</h3>
The latest version can be found at
<a href="http://luaforge.net/frs/?group_id=262">LuaForge</a>.
<h3>Compiling</h3>
To compile the module, just edit the <code>Makefile</code> to reflect your
installation of Lua. Then run make. This will build the library and run a simple test.
<h3>Installing</h3>
To intall the module, just copy
<code>syslog.so</code> somewhere in your
<a href="http://www.lua.org/pil/8.1.html">
<code>LUA_CPATH</code></a>.
<h3>Usage</h3>
The library exports the following Lua functions:
<ul>
<li><code>openlog(ident, option[, facility]) </code>
<li><code>syslog(priority, message) </code>
<li><code>closelog() </code>
</ul>
<p>See <code>test.lua</code>, which shows the library in action.
</p>
<p>You may want to wrap the standard <code>assert</code> and
<code>error</code> Lua calls so that they log the assertion or error before
aborting the program. This can be useful for post-mortem analysis of
embedded or unattended Lua applications. You can append this code at the end of
<code>strict.lua</code>, a module that can be found in the
<code>etc</code> directory of the Lua sources, and which is worth including
anyway.
</p>
<pre>
if pcall(require, "syslog") then -- only if syslog lib is avalible
-- set the ident string to the lua filename that first included this module
--local func_info = debug.getinfo(3, "S")
--if func_info then
-- syslog.openlog(func_info.short_src, syslog.LOG_ODELAY, "LOG_USER")
--end
-- make error call syslog.syslog too
local _error = error
_G.error = function(txt, level)
if level then
level = level + 1
else
level = 2
end
local info = debug.getinfo(level, "Sl")
local msg
if info.what == "C" then
msg = "[C function] "
else
msg = string.format("[%s]:%d ", info.short_src, info.currentline)
end
syslog.syslog("LOG_ERR", msg .. (txt or ""))
_error(txt, level)
end
-- make assert call our modified error function
_G.assert = function (...)
local cond, txt = ...
if not cond then
error(txt or "assertion failed!", 2)
end
return ...
end
end
</pre>
Then call <code>require "strict"</code> at the top of your code.
<h3>License</h3>
This code is hereby placed in the public domain.
Please send comments, suggestions, and bug reports to
<a href="mailto:[email protected]">[email protected]</a> .
<h3>Thanks</h3>
Thanks to <a href="http://www.tecgraf.puc-rio.br/~lhf>
Luiz Henrique de Figueiredo</a> for the Makefile.
</body>
</html>