1Mail::SpamAssassin::LogUgseerr(3C)ontributed Perl DocumeMnatialt:i:oSnpamAssassin::Logger(3)
2
3
4
6 Mail::SpamAssassin::Logger - SpamAssassin logging module
7
9 use Mail::SpamAssassin::Logger;
10
11 $SIG{__WARN__} = sub {
12 log_message("warn", $_[0]);
13 };
14
15 $SIG{__DIE__} = sub {
16 log_message("error", $_[0]) if !$^S;
17 };
18
20 add_facilities(facilities)
21 Enable debug logging for specific facilities. Each facility is the
22 area of code to debug. Facilities can be specified as a hash
23 reference (the key names are used), an array reference, an array,
24 or a comma-separated scalar string. Facility names are case-
25 sensitive.
26
27 If "all" is listed, then all debug facilities are implicitly
28 enabled, except for those explicitly disabled. A facility name may
29 be preceded by a "no" (case-insensitive), which explicitly disables
30 it, overriding the "all". For example: all,norules,noconfig,nodcc.
31 When facility names are given as an ordered list (array or scalar,
32 not a hash), the last entry applies, e.g. 'nodcc,dcc,dcc,noddc' is
33 equivalent to 'nodcc'. Note that currently no facility name starts
34 with a "no", it is advised to keep this practice with newly added
35 facility names to make life easier.
36
37 Higher priority informational messages that are suitable for
38 logging in normal circumstances are available with an area of
39 "info". Some very verbose messages require the facility to be
40 specifically enabled (see "would_log" below).
41
42 log_message($level, @message)
43 Log a message at a specific level. Levels are specified as
44 strings: "warn", "error", "info", and "dbg". The first element of
45 the message must be prefixed with a facility name followed directly
46 by a colon.
47
48 dbg("facility: message")
49 This is used for all low priority debugging messages.
50
51 info("facility: message")
52 This is used for informational messages indicating a normal, but
53 significant, condition. This should be infrequently called. These
54 messages are typically logged when SpamAssassin is run as a daemon.
55
56 add(method => 'syslog', socket => $socket, facility => $facility,
57 escape => $escape)
58 "socket" is the type the syslog ("unix" or "inet"). "facility" is
59 the syslog facility (typically "mail").
60
61 If optional "escape" is true, all non-ascii characters are escaped
62 for safe output: backslashes change to \\ and non-ascii chars to
63 \x{XX} or \x{XXXX} (Unicode). If not defined, pre-4.0 style
64 sanitizing is used ( tr/\x09\x20\x00-\x1f/_/s ).
65
66 Escape value can be overridden with environment variable
67 "SA_LOGGER_ESCAPE".
68
69 add(method => 'file', filename => $file, escape => $escape)
70 "filename" is the name of the log file. "escape" works as
71 described above.
72
73 add(method => 'stderr', escape => $escape)
74 No options are needed for stderr logging, just don't close stderr
75 first. "escape" works as described above.
76
77 remove(method)
78 Remove a logging method. Only the method name needs to be passed
79 as a scalar.
80
81 would_log($level, $facility)
82 Returns false if a message at the given level and with the given
83 facility would not be logged. Returns 1 if a message at a given
84 level and facility would be logged normally. Returns 2 if the
85 facility was specifically enabled.
86
87 The facility argument is optional.
88
89 close_log()
90 Close all logs.
91
92
93
94perl v5.38.0 2023-07-22 Mail::SpamAssassin::Logger(3)