| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 2 |
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 |
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 |
<head> |
| 5 |
<title>LuaLogging: A simple API to use logging features in Lua</title> |
| 6 |
<link rel="stylesheet" href="doc.css" type="text/css"/> |
| 7 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 8 |
</head> |
| 9 |
<body> |
| 10 |
|
| 11 |
<div id="container"> |
| 12 |
|
| 13 |
<div id="product"> |
| 14 |
<div id="product_logo"> |
| 15 |
<img alt="LuaLogging logo" src="images/lualogging-128.png"/> |
| 16 |
</div> |
| 17 |
<div id="product_name"><big><strong>LuaLogging</strong></big></div> |
| 18 |
<div id="product_description">A simple API to use logging features in Lua.</div> |
| 19 |
</div> <!-- id="product" --> |
| 20 |
|
| 21 |
<div id="main"> |
| 22 |
|
| 23 |
<div id="navigation"> |
| 24 |
<h1>LuaLogging</h1> |
| 25 |
<ul> |
| 26 |
<li><a href="index.html">Home</a></li> |
| 27 |
<li><a href="manual.html">Manual</a> |
| 28 |
<ul> |
| 29 |
<li><a href="manual.html#installation">Installation</a></li> |
| 30 |
<li><a href="manual.html#logger">Logger objects</a></li> |
| 31 |
<li><a href="manual.html#examples">Examples</a></li> |
| 32 |
</ul> |
| 33 |
</li> |
| 34 |
<li><a href="manual.html#appenders">Appenders</a> |
| 35 |
<ul> |
| 36 |
<li><a href="console.html">Console</a></li> |
| 37 |
<li><a href="file.html">File</a></li> |
| 38 |
<li><a href="rolling_file.html">Rolling File</a></li> |
| 39 |
<li><a href="sql.html">SQL</a></li> |
| 40 |
<li><a href="socket.html">Socket</a></li> |
| 41 |
<li><strong>Rsyslog</strong></li> |
| 42 |
<li><a href="email.html">Email</a></li> |
| 43 |
<li><a href="nginx.html">Nginx</a></li> |
| 44 |
</ul> |
| 45 |
</li> |
| 46 |
<li><a href="https://github.com/lunarmodules/lualogging">Project</a></li> |
| 47 |
<li><a href="license.html">License</a></li> |
| 48 |
</ul> |
| 49 |
</div> <!-- id="navigation" --> |
| 50 |
|
| 51 |
<div id="content"> |
| 52 |
|
| 53 |
<h2>Remote syslog appender</h2> |
| 54 |
|
| 55 |
<p>This appender can be used to send syslog formatted log requests to a remote syslog server. |
| 56 |
This appender relies on <a href="https://github.com/lunarmodules/luasocket">LuaSocket</a> |
| 57 |
to do its job. Optionally <a href="https://github.com/lunarmodules/copas">Copas</a> can be |
| 58 |
used for async sending of log messages over TCP.<br /></p> |
| 59 |
|
| 60 |
<p>If you want to log to the local syslog daemon, then please use |
| 61 |
<a href="https://github.com/lunarmodules/luasyslog">luasyslog</a>.</p> |
| 62 |
|
| 63 |
<p>The LuaLogging log-levels will be mapped to the syslog levels by their name, where |
| 64 |
<code>logging.FATAL</code> maps to syslog <code>ALERT</code>. Since LuaLogging only has 5 |
| 65 |
levels, the syslog levels <code>EMERG</code>, <code>CRIT</code>, and <code>NOTICE</code> |
| 66 |
remain unused.</p> |
| 67 |
|
| 68 |
<pre class="example"> |
| 69 |
function logging.rsyslog { |
| 70 |
hostname = <i>string</i>, |
| 71 |
[port = <i>number</i>,] |
| 72 |
[protocol = <i>"udp"</i> | <i>"tcp"</i>,] |
| 73 |
[rfc = <i>"rfc5424"</i> | <i>"rfc3164"</i>,] |
| 74 |
[maxsize = <i>number</i>,] |
| 75 |
[facility = <i>facility-constant</i>,] |
| 76 |
[ident = <i>string</i>,] |
| 77 |
[procid = <i>string</i>,] |
| 78 |
[msgid = <i>string</i>,] |
| 79 |
|
| 80 |
[logPattern = <i>string</i>,] |
| 81 |
[logPatterns = { |
| 82 |
[logging.DEBUG = <i>string</i>,] |
| 83 |
[logging.INFO = <i>string</i>,] |
| 84 |
[logging.WARN = <i>string</i>,] |
| 85 |
[logging.ERROR = <i>string</i>,] |
| 86 |
[logging.FATAL = <i>string</i>,] |
| 87 |
},] |
| 88 |
[logLevel = <i>log-level-constant</i>,] |
| 89 |
} |
| 90 |
</pre> |
| 91 |
|
| 92 |
<ul> |
| 93 |
<li><code>hostname</code>:<br /> |
| 94 |
Hostname can be an IP address or a host name of the server where the log |
| 95 |
message will be sent. |
| 96 |
</li> |
| 97 |
|
| 98 |
<li><code>port</code>:<br /> |
| 99 |
The port must be an integer number in the range [1..64K). The default is |
| 100 |
<code>514</code>. |
| 101 |
</li> |
| 102 |
|
| 103 |
<li><code>protocol</code>:<br /> |
| 104 |
The network protocol to use, either <code>"udp"</code> or <code>"tcp"</code>. |
| 105 |
The default is <code>"tcp"</code>. |
| 106 |
<br/><br/> |
| 107 |
Note: TCP sending is a blocking operation. For non-blocking use |
| 108 |
<a href="https://github.com/lunarmodules/copas">Copas</a> |
| 109 |
is supported, see the example below. |
| 110 |
</li> |
| 111 |
|
| 112 |
<li><code>rfc</code>:<br /> |
| 113 |
The message format. 2 options: |
| 114 |
<ul> |
| 115 |
<li>for the old BSD style use <code>"rfc3164"</code> (the default)</li> |
| 116 |
<li>for the IETF standard use <code>"rfc5424"</code>.</li> |
| 117 |
</ul> |
| 118 |
</li> |
| 119 |
|
| 120 |
<li><code>maxsize</code>:<br /> |
| 121 |
The maximum message size. Longer messages will be truncated. The minimum value is 480. |
| 122 |
The defaults are 1024 for <code>"rfc3164"</code>, and 2048 for <code>"rfc5424"</code>. |
| 123 |
</li> |
| 124 |
|
| 125 |
<li><code>facility</code>:<br /> |
| 126 |
The syslog facility to use, use one of the constants. The default value |
| 127 |
is the "user" facility. |
| 128 |
<pre class="example"> |
| 129 |
rsyslog.FACILITY_KERN |
| 130 |
rsyslog.FACILITY_USER |
| 131 |
rsyslog.FACILITY_MAIL |
| 132 |
rsyslog.FACILITY_DAEMON |
| 133 |
rsyslog.FACILITY_AUTH |
| 134 |
rsyslog.FACILITY_SYSLOG |
| 135 |
rsyslog.FACILITY_LPR |
| 136 |
rsyslog.FACILITY_NEWS |
| 137 |
rsyslog.FACILITY_UUCP |
| 138 |
rsyslog.FACILITY_CRON |
| 139 |
rsyslog.FACILITY_AUTHPRIV |
| 140 |
rsyslog.FACILITY_FTP |
| 141 |
rsyslog.FACILITY_NTP |
| 142 |
rsyslog.FACILITY_SECURITY |
| 143 |
rsyslog.FACILITY_CONSOLE |
| 144 |
rsyslog.FACILITY_NETINFO |
| 145 |
rsyslog.FACILITY_REMOTEAUTH |
| 146 |
rsyslog.FACILITY_INSTALL |
| 147 |
rsyslog.FACILITY_RAS |
| 148 |
rsyslog.FACILITY_LOCAL0 |
| 149 |
rsyslog.FACILITY_LOCAL1 |
| 150 |
rsyslog.FACILITY_LOCAL2 |
| 151 |
rsyslog.FACILITY_LOCAL3 |
| 152 |
rsyslog.FACILITY_LOCAL4 |
| 153 |
rsyslog.FACILITY_LOCAL5 |
| 154 |
rsyslog.FACILITY_LOCAL6 |
| 155 |
rsyslog.FACILITY_LOCAL7 |
| 156 |
</pre> |
| 157 |
</li> |
| 158 |
|
| 159 |
<li><code>ident</code>:<br /> |
| 160 |
The value for the APP-NAME field (rfc5424, called TAG field in rfc3164). |
| 161 |
Default value is <code>"lua"</code>. |
| 162 |
</li> |
| 163 |
|
| 164 |
<li><code>procid</code>:<br /> |
| 165 |
The process id value (only applicable for rfc5424 format). |
| 166 |
Default value is <code>"-"</code> (absent). |
| 167 |
</li> |
| 168 |
|
| 169 |
<li><code>msgid</code>:<br /> |
| 170 |
The message id value (only applicable for rfc5424 format). |
| 171 |
Default value is <code>"-"</code> (absent). |
| 172 |
</li> |
| 173 |
|
| 174 |
<li><code>logPattern</code>:<br /> |
| 175 |
This value will be used as the default value for each log-level that was |
| 176 |
omitted in <code>logPatterns</code>, this defaults to <code>"%message"</code>. |
| 177 |
The default pattern deviates from standard LuaLogging defaults since those |
| 178 |
do not make sense for syslog. |
| 179 |
</li> |
| 180 |
|
| 181 |
<li><code>logPatterns</code>:<br /> |
| 182 |
A table with logPattern strings indexed by the log-levels. |
| 183 |
A logPattern specifies how the message is written.<br /> |
| 184 |
If this parameter is omitted, a patterns table will be created with the |
| 185 |
parameter <code>logPattern</code> as the default value for each log-level. |
| 186 |
</li> |
| 187 |
|
| 188 |
<li><code>logLevel</code>:<br /> |
| 189 |
The initial log-level to set for the created logger. |
| 190 |
</li> |
| 191 |
</ul> |
| 192 |
|
| 193 |
<h2>Example</h2> |
| 194 |
|
| 195 |
<pre class="example"> |
| 196 |
local rsyslog = require "logging.rsyslog" |
| 197 |
|
| 198 |
rsyslog.copas() -- switch to using non-blocking Copas sockets |
| 199 |
|
| 200 |
local logger = rsyslog { |
| 201 |
hostname = "syslog.mycompany.com", |
| 202 |
port = 514, |
| 203 |
protocol = "tcp", |
| 204 |
rfc = "rfc5424", |
| 205 |
maxsize = 8000, |
| 206 |
facility = rsyslog.FACILITY_LOCAL2, |
| 207 |
ident = "my_lua_app", |
| 208 |
procid = "socket_mod", |
| 209 |
logPattern = "%message %source", |
| 210 |
} |
| 211 |
|
| 212 |
copas.loop(function() |
| 213 |
logger:info("logging.rsyslog test") |
| 214 |
logger:debug("debugging...") |
| 215 |
logger:error("error!") |
| 216 |
|
| 217 |
-- destroy to ensure threads are shutdown (only for Copas) |
| 218 |
logger:destroy() |
| 219 |
end) |
| 220 |
</pre> |
| 221 |
|
| 222 |
<p> </p> |
| 223 |
<p> </p> |
| 224 |
<p> </p> |
| 225 |
<p> </p> |
| 226 |
|
| 227 |
</div> <!-- id="content" --> |
| 228 |
|
| 229 |
</div> <!-- id="main" --> |
| 230 |
|
| 231 |
<div id="about"> |
| 232 |
</div> <!-- id="about" --> |
| 233 |
|
| 234 |
</div> <!-- id="container" --> |
| 235 |
|
| 236 |
</body> |
| 237 |
</html> |