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