configuration

logrotate.conf — Log rotation policy

Logrotate reads /etc/logrotate.conf and included snippets, commonly /etc/logrotate.d. A stanza selects logs and sets rotation criteria, retention count and compression. daily sets an eligibility interval, not a scheduler; rotate 7 retains seven rotated versions, not necessarily seven days. compress is not enabled by default upstream. Missing files and empty logs depend on directives. Local stanza options override applicable global ones; later global settings and include placement matter. Duplicate log definitions may error. A running service may keep writing an old inode after rename, requiring an approved reopen mechanism; copytruncate has a data-loss window. Use debug mode with private state and fixture logs; no rotation or scripts should run in debug. Real changes require authorized config ownership and a maintenance review; restore previous policy, but restore deleted data only from backups.

Formal Syntax & Structure

linux syntaxlinux
/path/to/log {    daily    rotate 7    compress    missingok    notifempty}

Parameters & Attributes

NameTypeDescription
dailydirectiveTime-based eligibility
rotatedirectiveNumber of rotated versions
compressdirectiveCompress rotated logs
missingokdirectiveAllow absent log
notifemptydirectiveSkip empty logs

Return Value

configuration or inspection

Debug plan or rotation results, depending on invocation.

Working Example

Example Snippetlinux
set -eud=$(mktemp -d)trap 'rm -rf -- "$d"' EXITprintf 'demo\n' > "$d/app.log"cat > "$d/logrotate.conf" <<EOF$d/app.log {    daily    rotate 7    compress    missingok    notifempty}EOFlogrotate -d -s "$d/state" "$d/logrotate.conf" > "$d/debug" 2>&1grep -F 'considering log' "$d/debug" >/dev/nullprintf 'demo\n' | cmp - "$d/app.log"test ! -e "$d/state"test ! -e "$d/app.log.1"printf 'debug plan accepted; log and state unchanged\n'
Linux Reference