Skip to content

Umstellen des Mailserver-Loggings von Journald auf klassische Logfiles

logging

Debian Trixie nutzt standardmäßig systemd-journald, um Logs zu speichern. Für Mailserver ist es jedoch üblich, Logs in klassische Logfiles zu schreiben, z.B. /var/log/mail.log für Postfix und /var/log/dovecot.log für Dovecot.

Das hat Vorteile:

  • Einfache Auswertung mit grep / tail
  • Integration in Tools wie fail2Ban
  • Saubere Rotation via logrotate

Um dies umzusetzen, verwenden wir rsyslog als Vermittler zwischen den Diensten und den Logfiles.

Installation und Start von rsyslog

apt install rsyslog
systemctl enable rsyslog
systemctl start rsyslog

Mail-Log in /var/log/mail.log schreiben

Alle Logs mit der Facility mail (Postfix, rspamd, andere Maildienste) werden in /var/log/mail.log geschrieben. Hier kein & stop, damit die Nachrichten zusätzlich noch im Systemlog (/var/log/syslog) erscheinen – praktisch für Systemanalysen.

cat <<CONF | tee /etc/rsyslog.d/50-default.conf >/dev/null
mail.*    -/var/log/mail.log
CONF

Dovecot-Log in eigenes Logfile schreiben

Dovecot-Logs werden separat in /var/log/dovecot.log geschrieben. & stop sorgt dafür, dass die Dovecot-Logs nicht zusätzlich in /var/log/mail.log oder /var/log/syslog landen – so bleibt alles sauber getrennt.

cat <<CONF | tee /etc/rsyslog.d/20-dovecot.conf >/dev/null
if $programname == 'dovecot' then /var/log/dovecot.log
& stop
CONF

Logrotation für Dovecot einrichten

Da das Logfile /var/log/dovecot.log sonst nie rotiert würde, erstellen wir eine eigene Logrotate-Datei.

cat <<CONF | tee /etc/logrotate.d/dovecot >/dev/null
/var/log/dovecot.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 640 root adm
    postrotate
        systemctl reload rsyslog > /dev/null 2>&1 || true
    endscript
}
CONF

Die Konfiguration testen wir mit logrotate -d.

logrotate -df /etc/logrotate.d/dovecot
warning: logrotate in debug mode does nothing except printing debug messages!  Consider using verbose mode (-v) instead if this is not what you want.

reading config file /etc/logrotate.d/dovecot
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /var/log/dovecot.log forced from command line empty log files are not rotated, (7 rotations), old logs are removed
considering log /var/log/dovecot.log
  Now: 2026-02-25 12:05
  Last rotated at 2026-02-25 09:16
  log does not need rotating (log is empty)

Hinweis Die Rotation für /var/log/mail.log wird bereits durch /etc/logrotate.d/rsyslog geregelt.

Dienste neu starten, damit Änderungen aktiv werden

Damit die Änderung wirksam werden, starten wie die folgenden Services neu.

systemctl restart rsyslog
systemctl restart dovecot
systemctl restart postfix

Ergebnis

Dienst Logfile Rotation
Postfix /var/log/mail.log über rsyslog
Rspamd /var/log/rspamd/rspamd.log eigene Datei
Dovecot /var/log/dovecot.log neu eingerichtet