Test / test (push) Canceled after 0s
Test / fuzz (./compat, FuzzParseFormat) (push) Canceled after 0s
Test / fuzz (./formatter, FuzzFormatJSON) (push) Canceled after 0s
Test / fuzz (./formatter, FuzzFormatTextPolicy) (push) Canceled after 0s
Test / fuzz (./sanitizer, FuzzSanitize) (push) Canceled after 0s
Test / fuzz (./sanitizer, FuzzSerializerJSON) (push) Canceled after 0s
A host that draws on the terminal (a TUI) cannot let the logger write to stdout or stderr, yet the records are worth showing inside the host. SetErrorHandler already covers internal diagnostics; SetConsoleWriter is its sibling for console output. - SetConsoleWriter(w) sends console output of every console_target to w, split's warn-and-above records included; nil restores stdout/stderr. It holds across ApplyConfig and is safe while logging. - One stored value: ApplyConfig and SetConsoleWriter publish the console writers through storeConsole; the processor's split branch now reads the stored warn writer instead of writing os.Stderr directly. - TestLoggerConsoleTargets becomes TestConsoleWriterTakesEveryTarget, which asserts where each target's records land; a second test checks that nil restores the configured writers. - README names both hooks for terminal hosts; the API doc's callback contract covers console writers. Verified: go build ./... ok; gofmt -l on changed files clean; go vet ./... ok; go test ./... ok (all four packages, under 1 s); go test -race on the new tests ok; mutation run 6 of 6 caught. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyaMAhyEzAp3ULLWJZG4jQ
49 lines
2.1 KiB
Go
49 lines
2.1 KiB
Go
package log
|
|
|
|
import (
|
|
"sync/atomic"
|
|
)
|
|
|
|
// State encapsulates the runtime state of the logger
|
|
type State struct {
|
|
// General state
|
|
IsInitialized atomic.Bool // Tracks successful initialization, not start of log processor
|
|
LoggerDisabled atomic.Bool // Tracks logger stop due to issues (e.g. disk full)
|
|
ShutdownCalled atomic.Bool // Tracks if Shutdown() has been called, a terminal state
|
|
DiskFullLogged atomic.Bool // Tracks if a disk full error has been logged to prevent log spam
|
|
DiskStatusOK atomic.Bool // Tracks if disk space and size limits are currently met
|
|
Started atomic.Bool // Tracks calls to Start() and Stop()
|
|
ProcessorExited atomic.Bool // Tracks if the processor goroutine is running or has exited
|
|
|
|
// Emit fast path: config mirrors refreshed by applyConfig and the
|
|
// lifecycle transitions. Level holds levelOff while emission is closed
|
|
Level atomic.Int64
|
|
Flags atomic.Int64
|
|
TraceDepth atomic.Int64
|
|
|
|
// Flushing state
|
|
flushRequestChan chan flushRequest // per processor; published under sendMu
|
|
|
|
// Outputs
|
|
CurrentFile atomic.Value // stores *os.File
|
|
StdoutWriter atomic.Value // stores *sink, the console writers
|
|
|
|
// File State
|
|
CurrentSize atomic.Int64 // Size of the current log file
|
|
EarliestFileTime atomic.Value // stores time.Time for retention
|
|
|
|
// Log state
|
|
ActiveLogChannel atomic.Value // stores chan logRecord
|
|
ProcStop atomic.Value // stores chan struct{}, closed to signal exit
|
|
ProcDone atomic.Value // stores chan struct{}, closed by the processor
|
|
DroppedLogs atomic.Uint64 // Counter for logs dropped since last heartbeat
|
|
TotalDroppedLogs atomic.Uint64 // Counter for total logs dropped since logger start
|
|
|
|
// Heartbeat statistics
|
|
HeartbeatSequence atomic.Uint64 // Counter for heartbeat sequence numbers
|
|
LoggerStartTime atomic.Value // Stores time.Time for uptime calculation
|
|
TotalLogsProcessed atomic.Uint64 // Counter for non-heartbeat logs successfully processed
|
|
TotalRotations atomic.Uint64 // Counter for successful log rotations
|
|
TotalDeletions atomic.Uint64 // Counter for successful log deletions (cleanup/retention)
|
|
}
|