| 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><strong>Console</strong></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><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>Console appender</h2> |
| 54 |
|
| 55 |
<p>Console is the simplest appender. It just writes the log messages |
| 56 |
to <code>io.stdout</code> or <code>io.stderr</code>.</p> |
| 57 |
|
| 58 |
<pre class="example"> |
| 59 |
function logging.console { |
| 60 |
[destination = "stdout"|"stderr",] |
| 61 |
|
| 62 |
[logPattern = <i>string</i>,] |
| 63 |
[logPatterns = { |
| 64 |
[logging.DEBUG = <i>string</i>,] |
| 65 |
[logging.INFO = <i>string</i>,] |
| 66 |
[logging.WARN = <i>string</i>,] |
| 67 |
[logging.ERROR = <i>string</i>,] |
| 68 |
[logging.FATAL = <i>string</i>,] |
| 69 |
},] |
| 70 |
[timestampPattern = <i>string</i>,] |
| 71 |
[logLevel = <i>log-level-constant</i>,] |
| 72 |
} |
| 73 |
</pre> |
| 74 |
|
| 75 |
<ul> |
| 76 |
<li><code>logPatterns</code>:<br /> |
| 77 |
A table with logPattern strings indexed by the log-levels. |
| 78 |
A logPattern specifies how the message is written.<br /> |
| 79 |
If this parameter is omitted, a patterns table will be created with the |
| 80 |
parameter <code>logPattern</code> as the default value for each log-level. |
| 81 |
If <code>logPattern</code> also is omitted then each level will fall back to |
| 82 |
the current default setting, see <code>logging.defaultLogPatterns</code>. |
| 83 |
</li> |
| 84 |
|
| 85 |
<li><code>logPattern</code>:<br /> |
| 86 |
This value will be used as the default value for each log-level that was |
| 87 |
omitted in <code>logPatterns</code>. |
| 88 |
</li> |
| 89 |
|
| 90 |
<li><code>timestampPattern</code>:<br /> |
| 91 |
This is an optional parameter that can be used to specify a date/time formatting |
| 92 |
in the log message. |
| 93 |
See <code>logging.date</code> for the format. |
| 94 |
The default is taken from <code>logging.defaultTimestampPattern()</code>.</li> |
| 95 |
|
| 96 |
<li><code>destination</code>:<br /> |
| 97 |
The destination stream, optional. The value can be either <code>"stdout"</code>, |
| 98 |
or <code>"stderr"</code>. The default is <code>stdout</code>.</li> |
| 99 |
|
| 100 |
<li><code>logLevel</code>:<br /> |
| 101 |
The initial log-level to set for the created logger.</li> |
| 102 |
|
| 103 |
</ul> |
| 104 |
|
| 105 |
<h2>Examples</h2> |
| 106 |
|
| 107 |
<pre class="example"> |
| 108 |
local ansicolors = require("ansicolors") -- https://github.com/kikito/ansicolors.lua |
| 109 |
local ll = require("logging") |
| 110 |
require "logging.console" |
| 111 |
|
| 112 |
-- set up the default logger to stderr + colorization |
| 113 |
ll.defaultLogger(ll.console { |
| 114 |
logLevel = ll.DEBUG, |
| 115 |
destination = "stderr", |
| 116 |
timestampPattern = "%y-%m-%d %H:%M:%S", |
| 117 |
logPatterns = { |
| 118 |
[ll.DEBUG] = ansicolors("%date%{cyan} %level %message %{reset}(%source)\n"), |
| 119 |
[ll.INFO] = ansicolors("%date %level %message\n"), |
| 120 |
[ll.WARN] = ansicolors("%date%{yellow} %level %message\n"), |
| 121 |
[ll.ERROR] = ansicolors("%date%{red bright} %level %message %{reset}(%source)\n"), |
| 122 |
[ll.FATAL] = ansicolors("%date%{magenta bright} %level %message %{reset}(%source)\n"), |
| 123 |
} |
| 124 |
}) |
| 125 |
|
| 126 |
local log = ll.defaultLogger() |
| 127 |
|
| 128 |
log:info("logging.console test") |
| 129 |
log:debug("debugging...") |
| 130 |
log:error("error!") |
| 131 |
</pre> |
| 132 |
|
| 133 |
<p> </p> |
| 134 |
<p> </p> |
| 135 |
<p> </p> |
| 136 |
<p> </p> |
| 137 |
<p> </p> |
| 138 |
<p> </p> |
| 139 |
<p> </p> |
| 140 |
|
| 141 |
</div> <!-- id="content" --> |
| 142 |
|
| 143 |
</div> <!-- id="main" --> |
| 144 |
|
| 145 |
<div id="about"> |
| 146 |
<p><a href="https://validator.w3.org/check?uri=referer"> |
| 147 |
<img src="https://www.w3.org/Icons/valid-xhtml10" alt="XHTML 1.0 válido!" height="31" width="88" /></a></p> |
| 148 |
</div> <!-- id="about" --> |
| 149 |
|
| 150 |
</div> <!-- id="container" --> |
| 151 |
|
| 152 |
</body> |
| 153 |
</html> |