Documentation
¶
Overview ¶
Package sutureslog implements a slog-based handler for suture events.
Note this is a separate module from suture to avoid forcing suture itself to require a Go version that has log/slog. That dependency is isolated to just this module. That means you must run a separate
go get github.com/thejerf/suture/sutureslog
Passing this as a logger for a Supervisor looks like:
// have some *slog.Logger called logger supervisor := suture.New( "my supervisor name", suture.Spec{ EventHook: sutureslog.Handler{Logger: logger}.MustHook(), }, )
Index ¶
Constants ¶
const ( // LogStopTimeout is logged for suture.EventBackoff. LogStopTimeout = "stopping service has timed out" // LogResume is logged for suture.EventResume LogResume = "supervisor has resumed restarting services" // LogBackoff is logged for suture.EventBackoff LogBackoff = "supervisor has entered backoff state" // LogServicePanic is logged for suture.EventServicePanic LogServicePanic = "service under supervision has panicked" // LogServiceTerminate is logged for // suture.EventServiceTerminate LogServiceTerminate = "service has terminated by returning" )
Variables ¶
var ErrNoHandlerSpecified = errors.New("no slog handler specified")
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct { StopTimeoutLevel slog.Leveler ServicePanicLevel slog.Leveler ServiceTerminateLevel slog.Leveler BackoffLevel slog.Leveler ResumeLevel slog.Leveler Logger *slog.Logger }
A Handler handles incoming events and manages logging them to slog.
Once a Supervisor starts running with a Hook from this handler, the values must not be changed.
If the slog.Leveler is left nil, a default level will be used. A minimal definition includes only a Handler.
For EventStopTimeout and EventServicePanic, this default level will be slog.LevelError.
For EventServiceTerminate, the default level is slog.LevelInfo.
For the rest it will be slog.LevelDebug.
For Services passed as logging values, if the service implements slog.LogValuer, that will be passed to slog. Otherwise, if it implements fmt.Stringer, it will be stringified using that. Otherwise, it will be passed as an Any value.
The log messages that will be emitted by each event correspond to the constants defined by this package; this can be used by something like github.com/thejerf/slogassert to validate proper functioning of your code. See sutureslog_test.go in this package for examples.