Course outline

Apache HTTPD / Trust, correctness, and reviewed change / Lesson 21

Piped logs and rotation recovery

Configure an illustrative piped log and verify rotation, process ownership and retention without losing diagnostic evidence.

About 3 min readContent reviewed
On this page

Lesson goals

  • Explain piped logging and rotatelogs ownership.
  • Choose a bounded rotation and retention strategy.
  • Test continuity and recovery in an isolated server.

Define the logging contract

Access logs provide operational evidence, but files grow and may contain sensitive request metadata. Define which fields are needed, who can read them, retention and deletion responsibilities before choosing rotation. Apache can pipe logs to an external program such as rotatelogs; the logging process, filesystem and collector become additional operational dependencies. Do not include credentials, cookies or unnecessary sensitive query data in the log format.

Pipe an illustrative access log

The first fragment uses rotatelogs with an hourly interval and a filename format containing the hour. It assumes the binary path, log directory, format nickname and permissions are valid in an isolated Apache installation. Review the exact command and executable ownership carefully: piped log programs are started by the server and can carry elevated privileges depending on deployment. Never make the executable or parent directories writable by untrusted users.

apache Pipe a lab access log through hourly rotation
CustomLog "|/usr/local/apache2/bin/rotatelogs /tmp/httpd-lab/access.%Y-%m-%d-%H.log 3600" combined

Paths and the combined format must exist in the isolated installation. Review executable ownership and privileges before deployment.

Choose filename and retention

Rotation creates new output files but is not itself a complete retention or backup policy. Use sufficient filename granularity for the chosen rotation schedule and size behavior, and verify disk capacity and collector discovery. The second fragment demonstrates read-only inspection of synthetic lab files; it does not delete or rotate them. Avoid circular overwrite options unless loss of older evidence is explicitly acceptable.

bash Inspect synthetic rotated files
ls -l /tmp/httpd-lab/access.*.log

The command is read-only and assumes a disposable lab directory. It does not enforce retention or delete files.

Plan failures and reloads

A log writer can fail because of permissions, disk exhaustion, an invalid executable path or downstream collection failure. Define alerts and a recovery procedure for each component, including what evidence may be missing. Test graceful reload and process restart with the installed Apache version. Do not assume a successful web response proves that logs reached long-term storage, or that an abrupt process termination performs cleanup.

Test continuity and privacy

In a disposable server, send identifiable synthetic requests before and after a short controlled rotation interval. Confirm both entries reach the intended files and collector, inspect permissions and timestamps, and test an invalid destination without touching production logs. Check that the format excludes secrets. Record the configuration and tool versions; a syntax check alone does not prove rotation, retention or collector ingestion.

Common errors and fixes

Rotation overwrites earlier evidence

Why it happens
Filename granularity or circular overwrite behavior was not understood.
How to fix it
Choose unique names and a documented retention policy.
Prevent it next time
Test multiple rotations with synthetic entries.

The logging program cannot write

Why it happens
The binary path, directory or permissions are incorrect.
How to fix it
Correct the reviewed executable and destination ownership.
Prevent it next time
Test startup and an invalid destination in isolation.

A log pipeline exposes secrets

Why it happens
The format captured credentials or sensitive request data.
How to fix it
Remove unnecessary fields and restrict log access.
Prevent it next time
Inspect synthetic requests and test redaction.

2 practice exercises

1. Does rotatelogs automatically define how long files are retained?

Show worked solution

No. Rotation and retention are separate operational decisions. Define collection, backup and deletion policies, verify capacity, and test multiple intervals using disposable logs.

2. Why is a writable piped-log executable directory dangerous?

Show worked solution

The server launches the program, potentially with elevated privileges. An untrusted writer could alter what is executed. Use a reviewed executable path and restrict ownership and permissions.

Key takeaways

  • Piped logs add process, storage and collection failure boundaries.
  • Test rotation continuity, retention and privacy separately.

Official references