feat(logging): optional rotating log file

Under systemd, journald held the only copy of archied's output, and
running it by hand left no record at all -- so "where are the logs?" had
no good answer, and the dashboard had no history to show from before it
connected. [log] adds a file destination alongside stderr, with
size-based rotation and retention done in-package rather than pulling in
a dependency for a few hundred lines.

A file that cannot be opened is reported and the daemon continues on
stderr: losing the durable copy is not worth refusing to start over.

reader.go owns the on-disk format so nothing else has to parse it, and
bounds every read -- tailing keeps the newest entries within a fixed
scan window, so pointing it at a large file cannot exhaust memory.
This commit is contained in:
sam committed 2026-08-04 01:44:56 +10:00
1 parent cbe02c1e6b
commit 449c925f29
6 files changed
+797

No files matched your search

+21
View File
@@ -38,6 +38,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/memory"
"github.com/samcharles93/archie-core/internal/memory/builtin"
"github.com/samcharles93/archie-core/internal/nell"
@@ -224,6 +225,26 @@ func run() int {
}
cfg := doc.Config
// Re-create the logger now the config is known. Everything above this
// point logs to stderr only, which is unavoidable: the log destination is
// itself configuration. A file that cannot be opened is reported and the
// daemon continues on stderr -- losing the durable copy must not take the
// daemon down with it.
fileLog, logCloser, logErr := logging.New(logging.Options{
File: cfg.Log.File,
MaxSizeMB: cfg.Log.MaxSizeMB,
Keep: cfg.Log.Keep,
Level: cfg.Log.Level,
Stderr: !cfg.Log.Quiet,
})
log = fileLog
defer func() { _ = logCloser.Close() }()
if logErr != nil {
log.Error("file logging disabled", "err", logErr)
} else if cfg.Log.File != "" {
log.Info("logging to file", "path", cfg.Log.File)
}
secrets, err := configuredSecretRegistry(&cfg, log)
if err != nil {
log.Error("configure secrets", "err", err)