Bug#1121807: ITP: dpkg monthly named logs via symlink (replace logrotate dependency)

"Oliver C." <[email protected]>
Newsgroups gmane.linux.debian.devel.dpkg.bugs
Message-ID <93f62e3b-4b55-4a2b-9953-a70525b2147b__31090.1882637822$1764730771$gmane$org@gmx.de>
Package: dpkg
Version: 1.22.21
Severity: wishlist

Dear Maintainer,

## Problem

Current dpkg.log rotation via `/etc/logrotate.d/dpkg` (monthly, rotate 
12) has several limitations:

1. Limited history: Only 12 months retained by default
2. logrotate dependency: Cron overhead, configuration complexity
3. No distro-long tracking: Current logs don't contain Debian version info
4. Manual cleanup complexity: `rm dpkg.log.*` vs explicit `rm dpkg-2025-*`
5. Tooling expectations: Scripts expect `dpkg.log`/`dpkg.log.1` pattern

## Proposal: Symlink-based Monthly Logs

Keep dpkg-core UNCHANGED. Use `/var/log/dpkg.log` as symlink to current
monthly file.
Optionally prepend Debian version to log filenames:

dpkg-trixie-2025-12.log ← /var/log/dpkg.log (symlink, current month 
UNCOMPRESSED)
dpkg-trixie-2025-11.log.gz (COMPRESSED)
dpkg-trixie-2025-10.log.gz (COMPRESSED)
dpkg-trixie-2025-09.log.gz (COMPRESSED)
dpkg-bookworm-2025-08.log.gz (COMPRESSED)
...
dpkg-bookworm-2024-12.log.gz (COMPRESSED)
...

Benefits:
✅ NO dpkg core changes (fopen("/var/log/dpkg.log") works transparently)
✅ NO logrotate dependency (1 cron.monthly job)
✅ Distro-long history WITH version info: zgrep upgrade /var/log/dpkg-*.log
✅ Manual control: rm /var/log/dpkg-trixie-*.log
✅ Atomic switches via rename()
✅ ~15kB/month compressed → 500kB/3 years (negligible)
✅ Works on embedded (RPi, IoT) without rotation complexity

## Implementation (Trivial)

1. dpkg.cfg.d/10-symlinklogs:

LOGFILE="/var/log/dpkg.log"


2. /etc/cron.monthly/dpkg-monthly:

#!/bin/bash
# Atomic monthly log switch with optional distro prefix
DISTRO=$(grep '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2)
YEAR=$(date +%Y)
MONTH=$(date +%m)
NEWLOG="/var/log/dpkg-${DISTRO}-${YEAR}-${MONTH}.log"
[ ! -f "$NEWLOG" ] && touch "$NEWLOG" && chown root:root "$NEWLOG" && 
chmod 644 "$NEWLOG"
# Atomic symlink switch
ln -sfT "$NEWLOG" /var/log/dpkg.log

# compression of OLD logs only:
find /var/log -name 'dpkg-*.log' -not -newermt "$(date +%Y-%m-01)" -exec 
gzip {} \;

3. Disable logrotate:

mv /etc/logrotate.d/dpkg /etc/logrotate.d/dpkg.disabled


## Usage example

zgrep upgrade /var/log/dpkg.log                     # Current month
zgrep upgrade /var/log/dpkg-trixie-2025-10.log      # Trixie, October 
2025 history only
zgrep upgrade /var/log/dpkg-*.log                   # All history
zgrep upgrade /var/log/dpkg-trixie-*.log            # Trixie only and 
everything since release
zgrep upgrade /var/log/dpkg-trixie-2025*.log        # Trixie and year 
2025 history only
rm /var/log/dpkg-bookworm-*.log                     # Delete Bookworm

## Migration from current system

for f in /var/log/dpkg.log*; do
     DISTRO=$(grep '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2)
     CREATEDATE=$(stat -c %y "$f" | cut -d' ' -f1 | sed 's/\./-/g')
     YEAR=${CREATEDATE:0:4}
     MONTH=${CREATEDATE:5:2}
     mv "$f" "/var/log/dpkg-${DISTRO}-${YEAR}-${MONTH}.log"
done
ln -sf /var/log/dpkg-$(grep '^VERSION_CODENAME=' /etc/os-release | cut 
-d= -f2)-$(date +%Y-%m).log /var/log/dpkg.log


## Addressing Concerns

Q: What about wrong system time?
A: systemd-timer (`OnCalendar=monthly`) or `hwclock`-based fallback

Q: Race conditions?
A: `ln -sfT` + file existence check = atomic

Q: Backward compatibility?
A: `/var/log/dpkg.log` works exactly as before

Q: Embedded systems?
A: No logrotate parsing/rotation → less complexity

Q: Alternative naming?
A: `/var/log/dpkg-current.log` more explicit (optional migration path)

## Why superior to logrotate

Feature                         | logrotate        | Symlink
--------------------------------|------------------|--------
Dependencies                    | cron + logrotate | cron only
History                         | 12 months        | Unlimited + Distro
Cleanup of time specific logs   | Complex          | rm dpkg-trixie-*
Distro tracking                 | None             | Native in filename
Size/Month                      | ~50kB            | ~15kB gz for last 
months and older
dpkg changes                    | None             | None

## Request

1. Ship monthly cron + symlink setup in dpkg package
2. Document in `dpkg(1)` manpage
3. Disable `/etc/logrotate.d/dpkg` by default
4. Optional: Migrate file naming from dpkg.log to dpkg-current.log over 
time, because its name is more intuitive (clearly indicating the current 
log)
5. Optional: Migrate location of dpkg-*.log files to /var/log/dpkg/ 
(dpkg.log symlink can stay in /var/log/)

This eliminates 25+ year old logrotate complexity while preserving all
compatibility. Modern storage makes unlimited history practical.

-- System Information:
Debian GNU/Linux 13 (trixie)
dpkg 1.22.21

Regards,
Oliver C.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.