MAILLOG_README.html revision 1.1.1.5 1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "https://www.w3.org/TR/html4/loose.dtd">
3
4 <html>
5
6 <head>
7
8 <title>Postfix logging to file or stdout</title>
9
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11 <link rel='stylesheet' type='text/css' href='postfix-doc.css'>
12
13 </head>
14
15 <body>
16
17 <h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix
18 logging to file or stdout</h1>
19
20 <hr>
21
22 <h2>Overview </h2>
23
24 <p> Postfix supports its own logging system as an alternative to
25 syslog (which remains the default). This is available with Postfix
26 version 3.4 or later. </p>
27
28 <p> Topics covered in this document: </p>
29
30 <ul>
31
32 <li><a href="#log-to-file">Configuring logging to file</a>
33
34 <li><a href="#log-to-stdout">Configuring logging to stdout</a>
35
36 <li><a href="#logrotate">Rotating logs </a>
37
38 <li><a href="#limitations">Limitations</a>
39
40 </ul>
41
42 <h2> <a name="log-to-file"> Configuring logging to file </a> </h2>
43
44 <p> Logging to file solves a usability problem for MacOS, and
45 eliminates multiple problems for systemd-based systems. </p>
46
47 <ol>
48
49 <li> <p> Add the following line to master.cf if not already present
50 (note: there must be no whitespace at the start of the line): </p>
51
52 <blockquote>
53 <pre>
54 postlog unix-dgram n - n - 1 postlogd
55 </pre>
56 </blockquote>
57
58 <p> Note: the service type "<b>unix-dgram</b>" was introduced with
59 Postfix 3.4. Remove the above line before backing out to an older
60 Postfix version. </p>
61
62 <li> <p> Configure Postfix to write logging, to, for example,
63 /var/log/postfix.log. See also the "<a href="#logrotate">Logfile
64 rotation</a>" section below for logfile management. </p>
65
66 <p> In the example below, specifying maillog_file_permissions is
67 optional (Postfix 3.9 and later). The default value is 0600, i.e.,
68 only the super-user can access the file; the value 0644 also
69 adds 'group' and 'other' read access. </p>
70
71 <blockquote>
72 <pre>
73 # postfix stop
74 # postconf maillog_file=/var/log/postfix.log
75 # postconf maillog_file_permissions=0644 # (Postfix 3.9 and later)
76 # postfix start
77 </pre>
78 </blockquote>
79
80 <p> By default, the logfile name must start with "/var" or "/dev/stdout"
81 (the list of allowed prefixes is configured with the maillog_file_prefixes
82 parameter). This safety mechanism limits the damage from a single
83 configuration mistake. </p>
84
85 </ol>
86
87 <h2> <a name="log-to-stdout"> Configuring logging to stdout </a> </h2>
88
89 <p> Logging to stdout is useful when Postfix runs in a container,
90 as it eliminates a syslogd dependency. </p>
91
92 <ol>
93
94 <li> <p> Add the following line to master.cf if not already present (note:
95 there must be no whitespace at the start of the line): </p>
96
97 <blockquote>
98 <pre>
99 postlog unix-dgram n - n - 1 postlogd
100 </pre>
101 </blockquote>
102
103 <p> Note: the service type "<b>unix-dgram</b>" was introduced with
104 Postfix 3.4. Remove the above line before backing out to an older
105 Postfix version. </p>
106
107 <li> <p> Configure main.cf with "maillog_file = /dev/stdout". </p>
108
109 <li> <p> Start Postfix with "<b>postfix start-fg</b>". </p>
110
111 </ol>
112
113 <h2> <a name="logrotate"> Rotating logs </a> </h2>
114
115 <p> The command "<b>postfix logrotate</b>" may be run by hand or
116 by a cronjob. It logs all errors, and reports errors to stderr if
117 run from a terminal. This command implements the following steps:
118 </p>
119
120 <ul>
121
122 <li> <p> Rename the current logfile by appending a suffix that
123 contains the date and time. This suffix is configured with the
124 maillog_file_rotate_suffix parameter (default: %Y%m%d-%H%M%S). </p>
125
126 <li> <p> Reload Postfix so that postlogd(8) immediately closes the
127 old logfile. </p>
128
129 <li> <p> After a brief pause, compress the old logfile. The compression
130 program is configured with the maillog_file_compressor parameter
131 (default: gzip). </p>
132
133 <li> <p> The next time it logs an event, postlogd(8) will create a
134 new logfile, with permissions specified with the maillog_file_permissions
135 parameter (default: 0600). </p>
136
137 </ul>
138
139 <p> Notes: </p>
140
141 <ul>
142
143 <li> <p> This command will not rotate a logfile with a pathname under
144 the /dev directory, such as /dev/stdout. </p>
145
146 <li> <p> This command does not (yet) remove old logfiles. </p>
147
148 </ul>
149
150 <h2> <a name="limitations">Limitations</a> </h2>
151
152 <p> Background: </p>
153
154 <ul>
155
156 <li> <p> Postfix consists of a number of daemon programs that run
157 in the background, as well as non-daemon programs for local mail
158 submission or Postfix management.
159
160 <li> <p> Logging to the Postfix logfile or stdout requires the Postfix
161 postlogd(8) service. This ensures that simultaneous logging from
162 different programs will not get mixed up. </p>
163
164 <li> <p> All Postfix programs can log to syslog, but not all programs
165 have sufficient privileges to use the Postfix logging service, and
166 many non-daemon programs must not log to stdout as that would corrupt
167 their output. </p>
168
169 </ul>
170
171 <p> Limitations: </p>
172
173 <ul>
174
175 <li> <p> Non-daemon Postfix programs will log errors to syslogd(8)
176 before they have processed command-line options and main.cf parameters.
177
178 <li> <p> If Postfix is down, the non-daemon programs postfix(1),
179 postsuper(1), postmulti(1), and postlog(1), will log directly to
180 $maillog_file. These programs expect to run with root privileges,
181 for example during Postfix start-up, reload, or shutdown.
182
183 <li> <p> Other non-daemon Postfix programs will never write directly
184 to $maillog_file (also, logging to stdout would interfere with the
185 operation of some of these programs). These programs can log to
186 postlogd(8) if they are run by the super-user, or if their executable
187 file has set-gid permission. Do not set this permission on programs
188 other than postdrop(1), postqueue(1), and (Postfix ≥ 3.7)
189 postlog(1).
190
191 </ul>
192
193 </body>
194
195 </html>
196