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
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package log
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/lixenwraith/log/formatter"
|
|
)
|
|
|
|
// Context carries caller-stamped values emitted with a record
|
|
type Context = formatter.Context
|
|
|
|
// ContextSlots is the number of correlation values a Context carries
|
|
const ContextSlots = formatter.ContextSlots
|
|
|
|
// logRecord represents a single log entry
|
|
type logRecord struct {
|
|
heartbeat bool
|
|
TimeStamp time.Time
|
|
Trace string
|
|
Args []any
|
|
Ctx Context
|
|
Flags int64
|
|
Level int64
|
|
}
|
|
|
|
// TimerSet holds all timers used in processLogs
|
|
type TimerSet struct {
|
|
flushTicker *time.Ticker
|
|
diskCheckTicker *time.Ticker
|
|
retentionTicker *time.Ticker
|
|
heartbeatTicker *time.Ticker
|
|
retentionChan <-chan time.Time
|
|
heartbeatChan <-chan time.Time
|
|
diskInterval time.Duration
|
|
}
|
|
|
|
// sink holds the console writers in one atomic.Value; warn takes split's
|
|
// warn-and-above records
|
|
type sink struct {
|
|
w io.Writer
|
|
warn io.Writer
|
|
}
|
|
|
|
// flushRequest belongs to one processor generation; the buffered reply permits
|
|
// completion even when the caller has already timed out.
|
|
type flushRequest struct {
|
|
done chan error
|
|
}
|