Add logToSyslog option for journald/syslog logging#3
Open
anpryl wants to merge 3 commits into
Open
Conversation
Lancache currently only supports file-based logging via the logPrefix option. On systemd-based systems like NixOS, logging to journald is preferable — it provides automatic rotation, structured querying via journalctl, and eliminates the need for logrotate configuration. Add a logToSyslog boolean option (default false) that sends all nginx log output to syslog via the unix socket /dev/log. Different nginx contexts use distinct syslog tags for easy filtering: - lancache (primary cache engine) - lancache-upstream (upstream redirect handler) - lancache-stream (TLS SNI passthrough) Also changes logPrefix type from str to nullOr str so it can be omitted when logToSyslog is enabled. An assertion ensures at least one logging method is configured. Fully backward compatible — existing configs with logPrefix continue to work unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nginx rejects syslog tags containing hyphens with: syslog "tag" only allows alphanumeric characters and underscore Replace lancache-upstream → lancache_upstream and lancache-stream → lancache_stream. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace 6 individual log target variables with a single logTarget function that generates both access and error log paths for each nginx context. Preserves the original file names for backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
logToSyslogboolean option (defaultfalse) that sends all nginx log output to syslog via the unix socket/dev/loginstead of files. On systemd-based systems like NixOS, journald captures syslog messages automatically — providing automatic rotation, structured querying viajournalctl, and eliminating the need for logrotate configuration.Changes
services.lancache.logToSyslog— whentrue, all 6 nginx log directives usesyslog:server=unix:/dev/log,facility=local6,tag=<tag>instead of file pathslogPrefixtype fromtypes.strtotypes.nullOr types.str— allows omitting it when syslog is enabledlogTargethelper function to reduce duplication across the 6 log directiveslancache— primary cache enginelancache_upstream— upstream redirect handlerlancache_stream— TLS SNI passthroughBackward compatibility
logToSyslogdefaults tofalse— existing configs are unaffectednullOr stris a superset ofstr— every existinglogPrefixvalue remains validaccess.log,upstream-access.log,stream-access.log, etc.)Usage
Filter logs with:
Test plan
logToSyslog = true— succeedslogToSyslog = falsewithlogPrefixset produces identical nginx config to upstream