Postfix logging to file or stdout


Overview

Postfix supports its own logging system as an alternative to syslog (which remains the default). This is available with Postfix version 3.4 or later.

Topics covered in this document:

Configuring logging to file

Logging to file solves a usability problem for MacOS, and eliminates multiple problems for systemd-based systems.

  1. Add the following line to master.cf if not already present (note: there must be no whitespace at the start of the line):

    postlog   unix-dgram n  -       n       -       1       postlogd
    

    Note: the service type "unix-dgram" was introduced with Postfix 3.4. Remove the above line before backing out to an older Postfix version.

  2. Configure Postfix to write logging, to, for example, /var/log/postfix.log. See also the "Logfile rotation" section below for logfile management.

    In the example below, specifying maillog_file_permissions is optional (Postfix 3.9 and later). The default value is 0600, i.e., only the super-user can access the file; the value 0644 also adds 'group' and 'other' read access.

    # postfix stop
    # postconf maillog_file=/var/log/postfix.log
    # postconf maillog_file_permissions=0644 # (Postfix 3.9 and later)
    # postfix start
    

    By default, the logfile name must start with "/var" or "/dev/stdout" (the list of allowed prefixes is configured with the maillog_file_prefixes parameter). This safety mechanism limits the damage from a single configuration mistake.

Configuring logging to stdout

Logging to stdout is useful when Postfix runs in a container, as it eliminates a syslogd dependency.

  1. Add the following line to master.cf if not already present (note: there must be no whitespace at the start of the line):

    postlog   unix-dgram n  -       n       -       1       postlogd
    

    Note: the service type "unix-dgram" was introduced with Postfix 3.4. Remove the above line before backing out to an older Postfix version.

  2. Configure main.cf with "maillog_file = /dev/stdout".

  3. Start Postfix with "postfix start-fg".

Rotating logs

The command "postfix logrotate" may be run by hand or by a cronjob. It logs all errors, and reports errors to stderr if run from a terminal. This command implements the following steps:

Notes:

Limitations

Background:

Limitations: