Skip to content

File logging support via --log-file option#682

Merged
joseluisq merged 2 commits into
3.xfrom
file-logging-support
May 31, 2026
Merged

File logging support via --log-file option#682
joseluisq merged 2 commits into
3.xfrom
file-logging-support

Conversation

@joseluisq
Copy link
Copy Markdown
Collaborator

Description

This PR adds support for File Logging to write log records to a file on disk, in addition to stderr. It is useful for production deployments where stderr is captured by a service manager, but a durable on-disk copy is also required.

--log-file <PATH> (SERVER_LOG_FILE): Filesystem path to stream log records to in addition to stderr. Missing parent directories are created on startup. The file is opened in append mode.

The file uses the format selected by --log-format (json by default) and the level selected by --log-level.
ANSI escape codes are always disabled for file output regardless of --log-with-ansi, so the file stays parsable.

Example

static-web-server \
    --port 8787 \
    --root ./my-public-dir \
    --log-level info \
    --log-format json \
    --log-file /var/log/sws/server.log

Note that SWS does not rotate the file itself, so an external tool such as logrotate could be used.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

@joseluisq joseluisq self-assigned this May 30, 2026
@joseluisq joseluisq added enhancement New feature or request general Related to general server configuration v3 v3.x release (upcoming) labels May 30, 2026
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com Bot commented May 30, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  src/settings/mod.rs  64% smaller
  src/logger.rs  11% smaller
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format
  docs/content/configuration/command-line-arguments.md Unsupported file format
  docs/content/configuration/environment-variables.md Unsupported file format
  docs/content/features/logging.md Unsupported file format
  src/settings/cli.rs  0% smaller
  src/settings/file.rs  0% smaller
  tests/file_logging.rs  0% smaller

@joseluisq joseluisq marked this pull request as ready for review May 31, 2026 00:06
@joseluisq joseluisq merged commit 9b95aca into 3.x May 31, 2026
29 checks passed
@joseluisq joseluisq deleted the file-logging-support branch May 31, 2026 00:16
@joseluisq joseluisq added this to the v3.0.0-beta-1 milestone May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request general Related to general server configuration v3 v3.x release (upcoming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant