File: rolling_file.html

package info (click to toggle)
lua-logging 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 512 kB
  • sloc: makefile: 16; sh: 3
file content (151 lines) | stat: -rw-r--r-- 4,983 bytes parent folder | download
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="https://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="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">
    <img alt="LuaLogging logo" src="images/lualogging-128.png"/>
  </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></li>
    <li><a href="manual.html">Manual</a>
      <ul>
        <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><strong>Rolling File</strong></li>
        <li><a href="sql.html">SQL</a></li>
        <li><a href="socket.html">Socket</a></li>
        <li><a href="rsyslog.html">Rsyslog</a></li>
        <li><a href="email.html">Email</a></li>
        <li><a href="nginx.html">Nginx</a></li>
      </ul>
    </li>
    <li><a href="https://github.com/lunarmodules/lualogging">Project</a></li>
    <li><a href="license.html">License</a></li>
  </ul>
</div> <!-- id="navigation" -->

<div id="content">

<h2>Rolling File appender</h2>

<p>The rolling file appender can be used to write log messages to a file. It
uses Lua I/O routines to do its job. The rolling file appender rolls over the logfile
once it has reached a certain size limit. It also mantains a maximum number of log files.</p>

<pre class="example">
function logging.rolling_file {
    [filename = <i>string</i>,]
    maxFileSize = <i>number</i>,
    [maxBackupIndex = <i>number</i>,]

    [logPattern = <i>string</i>,]
    [logPatterns = {
      [logging.DEBUG = <i>string</i>,]
      [logging.INFO  = <i>string</i>,]
      [logging.WARN  = <i>string</i>,]
      [logging.ERROR = <i>string</i>,]
      [logging.FATAL = <i>string</i>,]
    },]
    [timestampPattern = <i>string</i>,]
    [logLevel = <i>log-level-constant</i>,]
}
</pre>

<ul>
    <li><code>filename</code>:<br />
    The name of the file to be written to.<br />
     If the file cannot be opened for appending the logging request
    returns nil and an error message.<br />
    The default value is <code>"lualogging.log"</code>.</li>

    <li><code>maxFileSize</code>:<br />
    The max size of the file in bytes. Every time the file reaches this size
    it will rollover, generating a new clean log file and storing the old log
    on a filename.n, where n goes from 1 to the configured maxBackupIndex.<br />
    The more recent backup is the one with the lowest n on its filename.<br />
    Eg. test.log.1 (most recent backup) <br />
        test.log.2 (least recent backup)
    </li>

    <li><code>maxBackupIndex</code>:<br />
    The number of backup files that will be generated.
    The default value is <code>1</code>.</li>

    <li><code>logPatterns</code>:<br />
      A table with logPattern strings indexed by the log-levels.
      A logPattern specifies how the message is written.<br />
      If this parameter is omitted, a patterns table will be created with the
      parameter <code>logPattern</code> as the default value for each log-level.
      If <code>logPattern</code> also is omitted then each level will fall back to
      the current default setting, see <code>logging.defaultLogPatterns</code>.
    </li>

    <li><code>logPattern</code>:<br />
      This value will be used as the default value for each log-level that was
      omitted in <code>logPatterns</code>.
    </li>

    <li><code>timestampPattern</code>:<br />
      This is an optional parameter that can be used to specify a date/time formatting
      in the log message.
      See <code>logging.date</code> for the format.
      The default is taken from <code>logging.defaultTimestampPattern()</code>.</li>

    <li><code>logLevel</code>:<br />
      The initial log-level to set for the created logger.</li>
  </ul>

<h2>Example</h2>

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

local logger = logging.rolling_file {
    filename = "test.log",
    maxFileSize = 1024,
    maxBackupIndex = 5,
}

logger:info("logging.rolling_file test")
logger:debug("debugging...")
logger:error("error!")
</pre>

<p>&nbsp;</p>
<p>&nbsp;</p>

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

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

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

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

</body>
</html>