Debian Codegraph @

docs/logging.pod

raw
1 #
2 # read this with 'perldoc docs/logging.pod'
3 #
4
5 =head1 qpsmtpd logging; user documentation
6
7 Qpsmtpd has a modular logging system. Here's a few things you need to know:
8
9 * The built-in logging prints log messages to STDERR.
10 * A variety of logging plugins is included, each with its own behavior.
11 * When a logging plugin is enabled, the built-in logging is disabled.
12 * plugins/logging/warn mimics the built-in logging.
13 * Multiple logging plugins can be enabled simultaneously.
14
15 Read the POD within each logging plugin (perldoc plugins/logging/B<NAME>)
16 to learn if it tickles your fancy.
17
18 =head2 enabling plugins
19
20 To enable logging plugins, edit the file I<config/logging> and uncomment the
21 entries for the plugins you wish to use.
22
23 =head2 logging level
24
25 The 'master switch' for loglevel is I<config/loglevel>. Qpsmtpd and active
26 plugins will output all messages that are less than or equal to the value
27 specified. The log levels correspond to syslog levels:
28
29 LOGDEBUG = 7
30 LOGINFO = 6
31 LOGNOTICE = 5
32 LOGWARN = 4
33 LOGERROR = 3
34 LOGCRIT = 2
35 LOGALERT = 1
36 LOGEMERG = 0
37 LOGRADAR = 0
38
39 Level 6, LOGINFO, is the level at which most servers should start logging. At
40 level 6, each plugin should log one and occasionally two entries that
41 summarize their activity. Here's a few sample lines:
42
43 (connect) ident::geoip: SA, Saudi Arabia
44 (connect) ident::p0f: Windows 7 or 8
45 (connect) earlytalker: pass: remote host said nothing spontaneous
46 (data_post) domainkeys: skip: unsigned
47 (data_post) spamassassin: pass, Spam, 21.7 < 100
48 (data_post) dspam: fail: agree, Spam, 1.00 c
49 552 we agree, no spam please (#5.6.1)
50
51 Three plugins fired during the SMTP connection phase and 3 more ran during the
52 data_post phase. Each plugin emitted one entry stating their findings.
53
54 If you aren't processing the logs, you can save some disk I/O by reducing the
55 loglevel, so that the only messages logged are ones that indicate a human
56 should be taking some corrective action.
57
58 =head2 log location
59
60 If qpsmtpd is started using the distributed run file (cd ~smtpd; ./run), then
61 you will see the log entries printed to your terminal. This solution works
62 great for initial setup and testing and is the simplest case.
63
64 A typical way to run qpsmtpd is as a supervised process with daemontools. If
65 daemontools is already set up, setting up qpsmtpd may be as simple as:
66
67 C<ln -s /usr/home/smtpd /var/service/>
68
69 If svcscan is running, the symlink will be detected and tcpserver will
70 run the 'run' files in the ./ and ./log directories. Any log entries
71 emitted will get handled per the instructions in log/run. The default
72 location specified in log/run is log/main/current.
73
74 =head2 plugin loglevel
75
76 Most plugins support a loglevel argument after their config/plugins entry.
77 The value can be a whole number (N) or a relative number (+/-N), where
78 N is a whole number from 0-7. See the descriptions of each below.
79
80 C<ident/p0f loglevel 5>
81
82 C<ident/p0f loglevel -1>
83
84 ATTN plugin authors: To support loglevel in your plugin, you must store the
85 loglevel settings from the plugins/config entry $self->{_args}{loglevel}. A
86 simple and recommended example is as follows:
87
88 sub register {
89 my ( $self, $qp ) = (shift, shift);
90 $self->log(LOGERROR, "Bad arguments") if @_ % 2;
91 $self->{_args} = { @_ };
92 }
93
94 =head3 whole number
95
96 If loglevel is a whole number, then all log activity in the plugin is logged
97 at that level, regardless of the level the plugin author selected. This can
98 be easily understood with a couple examples:
99
100 The master loglevel is set at 6 (INFO). The mail admin sets a plugin loglevel
101 to 7 (DEBUG). No messages from that plugin are emitted because DEBUG log
102 entries are not <= 6 (INFO).
103
104 The master loglevel is 6 (INFO) and the plugin loglevel is set to 5 or 6. All
105 log entries will be logged because 5 is <= 6.
106
107 This behavior is very useful to plugin authors. While testing and monitoring
108 a plugin, they can set the level of their plugin to log everything. To return
109 to 'normal' logging, they just update their config/plugins entry.
110
111 =head3 relative
112
113 Relative loglevel arguments adjust the loglevel of each logging call within
114 a plugin. A value of I<loglevel +1> would make every logging entry one level
115 less severe, where a value of I<loglevel -1> would make every logging entry
116 one level more severe.
117
118 For example, if a plugin has a loglevel setting of -1 and that same plugin
119 logged a LOGDEBUG, it would instead be a LOGINFO message. Relative values
120 makes it easy to control the verbosity and/or severity of individual plugins.
121
122 =head1 qpsmtpd logging system; developer documentation
123
124 Qpsmtpd now (as of 0.30-dev) supports a plugable logging architecture, so
125 that different logging plugins can be supported. See the example logging
126 plugins in plugins/logging, specifically the L<plugins/logging/warn> and
127 L<plugins/logging/adaptive> files for examples of how to write your own
128 logging plugins.
129
130 =head1 plugin authors
131
132 While plugins can log anything they like, a few logging conventions in use:
133
134 =over 4
135
136 =item * at LOGINFO, log a single entry summarizing their disposition
137
138 =item * log messages are prefixed with keywords: pass, fail, skip, error
139
140 =over 4
141
142 =item pass: tests were run and the message passed
143
144 =item fail: tests were run and the message failed
145
146 =item fail, tolerated: tests run, msg failed, reject disabled
147
148 =item skip: tests were not run
149
150 =item error: tried to run tests but failure(s) encountered
151
152 =item info: additional info, not to be used for plugin summary
153
154 =back
155
156 =item * when tests fail and reject is disabled, use the 'fail, tolerated' prefix
157
158 =back
159
160 When these conventions are adhered to, the logs/summarize tool outputs each
161 message as a single row, with a small x showing failed tests and a large X
162 for failed tests that caused message rejection.
163
164 =head1 Internal support for pluggable logging
165
166 Any code in the core can call C<$self->log()> and those log lines will be
167 dispatched to each of the registered logging plugins. When C<log()> is
168 called from a plugin, the plugin and hook names are automatically included
169 in the parameters passed the logging hooks. All plugins which register for
170 the logging hook should expect the following parameters to be passed:
171
172 $self, $transaction, $trace, $hook, $plugin, @log
173
174 where those terms are:
175
176 =over 4
177
178 =item C<$self>
179
180 The object which was used to call the log() method; this can be any object
181 within the system, since the core code will automatically load logging
182 plugins on behalf of any object.
183
184 =item C<$transaction>
185
186 This is the current SMTP transaction (defined as everything that happens
187 between HELO/EHLO and QUIT/RSET). If you want to defer outputting certain
188 log lines, you can store them in the transaction object, but you will need
189 to bind the C<reset_transaction> hook in order to retrieve that information
190 before it is discarded when the transaction is closed (see the
191 L<logging/adaptive> plugin for an example of doing this).
192
193 =item C<$trace>
194
195 This is the log level (as shown in config.sample/loglevel) that the caller
196 asserted when calling log(). If you want to output the textural
197 representation (e.g. C<LOGERROR>) of this in your log messages, you can use
198 the log_level() function exported by Qpsmtpd::Constants (which is
199 automatically available to all plugins).
200
201 =item C<$hook>
202
203 This is the hook that is currently being executed. If log() is called by
204 any core code (i.e. not as part of a hook), this term will be C<undef>.
205
206 =item C<$plugin>
207
208 This is the plugin name that executed the log(). Like C<$hook>, if part of
209 the core code calls log(), this wil be C<undef>. See L<logging/warn> for a
210 way to prevent logging your own plugin's log entries from within that
211 plugin (the system will not infinitely recurse in any case).
212
213 =item C<@log>
214
215 The remaining arguments are as passed by the caller, which may be a single
216 term or may be a list of values. It is usually sufficient to call
217 C<join(" ",@log)> to deal with these terms, but it is possible that some
218 plugin might pass additional arguments with signficance.
219
220 =back
221
222 Note: if you register a handler for certain hooks, e.g. C<deny>, there may
223 be additional terms passed between C<$self> and C<$transaction>. See
224 L<logging/adaptive> for and example.
225