Documentation
¶
Overview ¶
Package logfiles wires per-component dated log files for wick runtimes that own their own process (tray on GUI hosts, headless `all` spawned by `wick start`). It opens app/server/worker/mcp files under ~/.<appName>/logs/, pipes os.Stdout / os.Stderr into app.log so fmt.Printf and panic traces survive when the real console is detached, and prunes files older than the retention window.
Layout:
~/.<appName>/logs/ app-YYYY-MM-DD.log // tray / startup / global zerolog + stdout/stderr server-YYYY-MM-DD.log // HTTP server (zerolog component=server) worker-YYYY-MM-DD.log // job worker (zerolog component=worker) mcp-YYYY-MM-DD.log // wickmanager MCP audit
Each file is tee'd to the original stderr so an interactive operator still sees output in the terminal. When the caller has no real stderr (tray detaches the console, daemon redirects to daemon-DATE.log), the file is the only sink — that's the intent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithOriginalStdio ¶ added in v1.2.9
WithOriginalStdio runs fn with os.Stdout / os.Stderr temporarily restored to the process's real stdio.
This exists for forking a successor during a graceful upgrade. The fork hands the child os.Stdout / os.Stderr as they are at that moment, and after Setup those are OUR log pipes — read by goroutines that die with this process. The child would inherit fd 1 and 2 pointing at pipes nobody reads, and Go makes SIGPIPE on fd 1/2 fatal: the successor was dying seconds after a perfectly clean handoff. It also meant the child's early output was copied into the parent's log file, so every boot line appeared twice.
The swap is brief and only affects direct writers to os.Stdout/os.Stderr during the fork; the loggers write to their files either way.
Types ¶
type Set ¶
type Set struct {
App zerolog.Logger
Server zerolog.Logger
Worker zerolog.Logger
MCP zerolog.Logger
Dir string
}
Set bundles the per-component loggers produced by Setup. Callers wire each logger into the relevant subsystem (server / worker / mcp) and use App as the global zerolog default.
func Setup ¶
Setup creates the dated log files, installs stdout/stderr pipes that funnel fmt.Printf and panic traces into app.log, points the global zerolog log.Logger and stdlib log at the App logger, and returns a cleanup func that flushes the pipe goroutines then closes all files. retentionDays <= 0 falls back to the default (1 day).