Documentation
¶
Overview ¶
Package graceful provides a Logger implementation using Go's log/slog.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface {
Infof(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
Logger interface is used throughout gorush
func NewSlogLogger ¶ added in v1.2.0
func NewSlogLogger(opts ...SlogLoggerOption) Logger
NewSlogLogger creates a Logger using flexible option pattern.
Usage:
NewSlogLogger() // text mode (default) NewSlogLogger(WithJSON()) // json mode NewSlogLogger(WithSlog(loggerObj)) // inject custom *slog.Logger, which overrides other options
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the graceful shutdown process
func NewManagerWithContext ¶ added in v0.0.2
NewManagerWithContext initial the Manager with custom context
func (*Manager) AddRunningJob ¶
func (g *Manager) AddRunningJob(f RunningJob)
AddRunningJob add running task
func (*Manager) AddShutdownJob ¶ added in v0.0.2
func (g *Manager) AddShutdownJob(f ShtdownJob)
AddShutdownJob add shutdown task
func (*Manager) Done ¶
func (g *Manager) Done() <-chan struct{}
Done allows the manager to be viewed as a context.Context.
func (*Manager) ShutdownContext ¶ added in v0.0.4
ShutdownContext returns a context.Context that is Done at shutdown
type OptionFunc ¶ added in v0.1.0
type OptionFunc func(*Options)
OptionFunc is a function that configures a graceful shutdown.
func (OptionFunc) Apply ¶ added in v0.1.0
func (f OptionFunc) Apply(option *Options)
Apply calls f(option)
type Options ¶ added in v0.1.0
type Options struct {
// contains filtered or unexported fields
}
Options for graceful shutdown
type RunningJob ¶
type ShtdownJob ¶ added in v0.0.2
type ShtdownJob func() error
type SlogLoggerOption ¶ added in v1.2.0
type SlogLoggerOption func(*slogLoggerOptions)
SlogLoggerOption applies configuration to NewSlogLogger.
func WithJSON ¶ added in v1.2.0
func WithJSON() SlogLoggerOption
WithJSON returns an option to set output as JSON format.
func WithSlog ¶ added in v1.2.0
func WithSlog(logger *slog.Logger) SlogLoggerOption
WithSlog injects a custom *slog.Logger instance.