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