| 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><strong>SQL</strong></li> |
| 40 |
<li><a href="socket.html">Socket</a></li> |
| 41 |
<li><a href="rsyslog.html">Rsyslog</a></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>SQL appender</h2> |
| 54 |
|
| 55 |
<p>The SQL appender can be used to write log messages to a SQL |
| 56 |
database table. It uses <a href="https://keplerproject.github.io/luasql/">LuaSQL</a>, |
| 57 |
therefore any database supported by LuaSQL can be used.</p> |
| 58 |
|
| 59 |
<pre class="example"> |
| 60 |
function logging.sql{ |
| 61 |
connectionfactory = <i>function</i>, |
| 62 |
[tablename = <i>string</i>,] |
| 63 |
[logdatefield = <i>string</i>,] |
| 64 |
[loglevelfield = <i>string</i>,] |
| 65 |
[logmessagefield = <i>string</i>,] |
| 66 |
[keepalive = <i>boolean</i>,] |
| 67 |
|
| 68 |
[logLevel = <i>log-level-constant</i>,] |
| 69 |
} |
| 70 |
</pre> |
| 71 |
|
| 72 |
<ul> |
| 73 |
<li><code>connectionfactory</code>:<br /> |
| 74 |
This must be a function that creates a LuaSQL connection object. |
| 75 |
This function will be called everytime a connection needs to be |
| 76 |
created.</li> |
| 77 |
|
| 78 |
<li><code>tablename</code>:<br /> |
| 79 |
The name of the table to write the log requests. Default value is |
| 80 |
<code>"LogTable"</code>.</li> |
| 81 |
|
| 82 |
<li><code>logdatefield</code>:<br /> |
| 83 |
The name of the field to write the date of each log request. |
| 84 |
Default value is <code>"LogDate"</code>.</li> |
| 85 |
|
| 86 |
<li><code>loglevelfield</code>:<br /> |
| 87 |
The name of the field to write the level of each log request. |
| 88 |
Default value is <code>"LogLevel"</code>.</li> |
| 89 |
|
| 90 |
<li><code>logmessagefield</code>:<br /> |
| 91 |
The name of the field to write the message of each log request. |
| 92 |
Default value is <code>"LogMessage"</code>.</li> |
| 93 |
|
| 94 |
<li><code>keepalive</code>:<br /> |
| 95 |
In every log request a connection to the database is opened, the |
| 96 |
message is written, and the connection is closed.<br /> |
| 97 |
If the user wants to keep the connection opened he can specify |
| 98 |
<code>keepalive = true</code>.</li> |
| 99 |
|
| 100 |
<li><code>logLevel</code>:<br /> |
| 101 |
The initial log-level to set for the created logger.</li> |
| 102 |
</ul> |
| 103 |
|
| 104 |
<h2>Example</h2> |
| 105 |
|
| 106 |
<pre class="example"> |
| 107 |
require"logging.sql" |
| 108 |
require"luasql.jdbc" |
| 109 |
|
| 110 |
local env, err = luasql.jdbc('com.mysql.jdbc.Driver') |
| 111 |
|
| 112 |
local logger = logging.sql { |
| 113 |
connectionfactory = function() |
| 114 |
local con, err = env:connect('jdbc:mysql://localhost/test', |
| 115 |
'tcp', '123') |
| 116 |
assert(con, err) |
| 117 |
return con |
| 118 |
end, |
| 119 |
keepalive = true, |
| 120 |
} |
| 121 |
|
| 122 |
logger:info("logging.sql test") |
| 123 |
logger:debug("debugging...") |
| 124 |
logger:error("error!") |
| 125 |
</pre> |
| 126 |
|
| 127 |
</div> <!-- id="content" --> |
| 128 |
|
| 129 |
</div> <!-- id="main" --> |
| 130 |
|
| 131 |
<div id="about"> |
| 132 |
</div> <!-- id="about" --> |
| 133 |
|
| 134 |
</div> <!-- id="container" --> |
| 135 |
|
| 136 |
</body> |
| 137 |
</html> |