Documentation
¶
Index ¶
- func Critical(ctx context.Context, msg string, params ...interface{})
- func Debug(ctx context.Context, msg string, params ...interface{})
- func Error(ctx context.Context, msg string, params ...interface{})
- func FromError(ctx context.Context, msg string, err error, params ...interface{})
- func Info(ctx context.Context, msg string, params ...interface{})
- func Log(evs ...Event)
- func Params(ctx context.Context) map[string]string
- func SetDefaultLogger(l Logger)
- func Trace(ctx context.Context, msg string, params ...interface{})
- func Warn(ctx context.Context, msg string, params ...interface{})
- func WithParam(ctx context.Context, key, value string) context.Context
- func WithParams(parent context.Context, params map[string]string) context.Context
- type Event
- type EventSet
- type FromErrorLogger
- type InMemoryLogger
- type LeveledLogger
- type Logger
- type MockLogger
- func (m *MockLogger) Critical(ctx context.Context, msg string, params ...interface{})
- func (m *MockLogger) Debug(ctx context.Context, msg string, params ...interface{})
- func (m *MockLogger) Error(ctx context.Context, msg string, params ...interface{})
- func (m *MockLogger) Info(ctx context.Context, msg string, params ...interface{})
- func (m *MockLogger) Trace(ctx context.Context, msg string, params ...interface{})
- func (m *MockLogger) Warn(ctx context.Context, msg string, params ...interface{})
- type MultiLogger
- type Severity
- type SeverityLogger
- func (s SeverityLogger) Critical(ctx context.Context, msg string, params ...interface{})
- func (s SeverityLogger) Debug(ctx context.Context, msg string, params ...interface{})
- func (s SeverityLogger) Error(ctx context.Context, msg string, params ...interface{})
- func (s SeverityLogger) Info(ctx context.Context, msg string, params ...interface{})
- func (s SeverityLogger) Trace(ctx context.Context, msg string, params ...interface{})
- func (s SeverityLogger) Warn(ctx context.Context, msg string, params ...interface{})
- type StdlibLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Critical ¶
Critical constructs a logging event with critical severity. If the default Logger implements the LeveledLogger interface, we forward the requests via the Critical interface function. If not, the event is sent via the default Logger
func Debug ¶
Debug constructs a logging event with debug severity. If the default Logger implements the LeveledLogger interface, we forward the requests via the Debug interface function. If not, the event is sent via the default Logger
func Error ¶
Error constructs a logging event with error severity. If the default Logger implements the LeveledLogger interface, we forward the requests via the Error interface function. If not, the event is sent via the default Logger
func FromError ¶
FromError constructs a logging event with error severity by default. If the default Logger implements the FromErrorLogger interface, we forward the requests via the FromError interface function. In this case the severity will be inferred from the error.
func Info ¶
Info constructs a logging event with info severity. If the default Logger implements the LeveledLogger interface, we forward the requests via the Info interface function. If not, the event is sent via the default Logger
func Params ¶
Params returns all parameters stored in the given context using WithParams. This function is intended to be used by libraries _other_ than slog that want access to the set of parameters (e.g. `monzo/terrors` functions).
The return value is guaranteed to be non-nil and can be safely mutated by the caller.
func SetDefaultLogger ¶
func SetDefaultLogger(l Logger)
func Trace ¶
Trace constructs a logging event with trace severity. If the default Logger implements the LeveledLogger interface, we forward the requests via the Trace interface function. If not, the event is sent via the default Logger
func Warn ¶
Warn constructs a logging event with warn severity. If the DefaultLogger implements the LeveledLogger interface, we forward the requests via the Warn interface function. If not, the event is sent via the default Logger
func WithParams ¶
WithParams returns a copy of the parent context containing the given log parameters. Any log events generated using the returned context will include these parameters as metadata.
For example:
ctx := slog.WithParams(ctx, map[string]string{ "foo_id": fooID, "bar_id": barID, }) slog.Info(ctx, "Linking foo to bar") // includes foo_id and bar_id parameters
If the parent context already contains parameters set by a previous call to WithParams, the new parameters will be merged with the existing set, with newer values taking precedence over older ones.
It is not safe to modify the supplied map after passing it to WithParams.
Types ¶
type Event ¶
type Event struct { Context context.Context `json:"-"` Id string `json:"id"` Timestamp time.Time `json:"timestamp"` Severity Severity `json:"severity"` Message string `json:"message"` OriginalMessage string `json:"-"` // Metadata are structured key-value pairs which describe the event. Metadata map[string]interface{} `json:"meta,omitempty"` // Labels, like Metadata, are key-value pairs which describe the event. Unlike Metadata, these are intended to be // indexed. Labels map[string]string `json:"labels,omitempty"` Error interface{} `json:"error,omitempty"` }
An Event is a discrete logging event
type FromErrorLogger ¶
type FromErrorLogger interface {
FromError(ctx context.Context, msg string, err error, params ...interface{})
}
FromErrorLogger is a logger which logs errors. The severity of the log is inferred from the error.
type InMemoryLogger ¶
func NewInMemoryLogger ¶
func NewInMemoryLogger() *InMemoryLogger
NewInMemoryLogger creates a logger that will keep all log events in memory Call InMemoryLogger.Events to access all logged events
func (*InMemoryLogger) Events ¶
func (l *InMemoryLogger) Events() EventSet
func (*InMemoryLogger) Flush ¶
func (l *InMemoryLogger) Flush() error
func (*InMemoryLogger) Log ¶
func (l *InMemoryLogger) Log(evs ...Event)
type LeveledLogger ¶
type LeveledLogger interface { Critical(ctx context.Context, msg string, params ...interface{}) Error(ctx context.Context, msg string, params ...interface{}) Warn(ctx context.Context, msg string, params ...interface{}) Info(ctx context.Context, msg string, params ...interface{}) Debug(ctx context.Context, msg string, params ...interface{}) Trace(ctx context.Context, msg string, params ...interface{}) }
LeveledLogger is a logger which logs at different levels.
type Logger ¶
A Logger is a way of outputting events.
func DefaultLogger ¶
func DefaultLogger() Logger
type MockLogger ¶
func (*MockLogger) Critical ¶
func (m *MockLogger) Critical(ctx context.Context, msg string, params ...interface{})
func (*MockLogger) Debug ¶
func (m *MockLogger) Debug(ctx context.Context, msg string, params ...interface{})
func (*MockLogger) Error ¶
func (m *MockLogger) Error(ctx context.Context, msg string, params ...interface{})
func (*MockLogger) Info ¶
func (m *MockLogger) Info(ctx context.Context, msg string, params ...interface{})
type SeverityLogger ¶
type SeverityLogger struct {
Logger
}
SeverityLogger is a logger which can log at different severity levels.
func NewSeverityLogger ¶
func NewSeverityLogger() SeverityLogger
NewSeverityLogger creates a SeverityLogger which wraps the default logger.
func (SeverityLogger) Critical ¶
func (s SeverityLogger) Critical(ctx context.Context, msg string, params ...interface{})
Critical writes a Critical event to the logger.
func (SeverityLogger) Debug ¶
func (s SeverityLogger) Debug(ctx context.Context, msg string, params ...interface{})
Debug writes a Debug event to the logger.
func (SeverityLogger) Error ¶
func (s SeverityLogger) Error(ctx context.Context, msg string, params ...interface{})
Error writes a Error event to the logger.
func (SeverityLogger) Info ¶
func (s SeverityLogger) Info(ctx context.Context, msg string, params ...interface{})
Info writes a Info event to the logger.
type StdlibLogger ¶
type StdlibLogger struct{}
StdlibLogger is a very simple logger which forwards events to Go's standard library logger
func (StdlibLogger) Flush ¶
func (s StdlibLogger) Flush() error
func (StdlibLogger) Log ¶
func (s StdlibLogger) Log(evs ...Event)