Documentation ¶
Overview ¶
Package log exposes a minimal interface for structured logging. It supports log key/value pairs passed through context
Index ¶
- func Debug(ctx context.Context, msg string)
- func Debugf(ctx context.Context, msg string, params ...interface{})
- func Error(ctx context.Context, msg string)
- func Errorf(ctx context.Context, msg string, params ...interface{})
- func Fatal(ctx context.Context, msg string)
- func Fatalf(ctx context.Context, msg string, params ...interface{})
- func Info(ctx context.Context, msg string)
- func Infof(ctx context.Context, msg string, params ...interface{})
- func SimplifyFields(fields map[string]interface{}) map[string]interface{}
- type CallbackLogger
- func (sl *CallbackLogger) AddCollector(collector ContextCollector)
- func (sl CallbackLogger) Debug(ctx context.Context, msg string)
- func (sl CallbackLogger) DebugContext(ctx context.Context, msg string, args ...any)
- func (sl CallbackLogger) Error(ctx context.Context, msg string)
- func (sl CallbackLogger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (sl CallbackLogger) Info(ctx context.Context, msg string)
- func (sl CallbackLogger) InfoContext(ctx context.Context, msg string, args ...any)
- type ContextCollector
- type FieldContextProvider
- type LogFunc
- type Logger
- type MapContext
- type TraceContext
- type TraceContextProvider
- type WrappedContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
Fatal logs, then causes the current program to exit status 1 The program terminates immediately; deferred functions are not run.
func Fatalf ¶
Fatalf logs, then causes the current program to exit status 1 The program terminates immediately; deferred functions are not run.
func SimplifyFields ¶
Types ¶
type CallbackLogger ¶
type CallbackLogger struct { Callback LogFunc Collectors []ContextCollector }
func NewCallbackLogger ¶
func NewCallbackLogger(callback LogFunc) *CallbackLogger
func (*CallbackLogger) AddCollector ¶
func (sl *CallbackLogger) AddCollector(collector ContextCollector)
func (CallbackLogger) DebugContext ¶
func (sl CallbackLogger) DebugContext(ctx context.Context, msg string, args ...any)
func (CallbackLogger) ErrorContext ¶
func (sl CallbackLogger) ErrorContext(ctx context.Context, msg string, args ...any)
func (CallbackLogger) InfoContext ¶
func (sl CallbackLogger) InfoContext(ctx context.Context, msg string, args ...any)
type ContextCollector ¶
type FieldContextProvider ¶
type FieldContextProvider interface { WithFields(context.Context, map[string]interface{}) context.Context ContextCollector }
var DefaultContext FieldContextProvider = &MapContext{}
type Logger ¶
type Logger interface { Debug(context.Context, string) Info(context.Context, string) Error(context.Context, string) AddCollector(ContextCollector) ErrorContext(ctx context.Context, msg string, args ...any) }
var DefaultLogger Logger = NewCallbackLogger(JSONLog(os.Stderr))
type MapContext ¶
type MapContext struct{}
func (MapContext) LogFieldsFromContext ¶
func (sc MapContext) LogFieldsFromContext(ctx context.Context) map[string]interface{}
func (MapContext) WithFields ¶
type TraceContext ¶
type TraceContext struct{}
func (TraceContext) FromContext ¶
func (sc TraceContext) FromContext(ctx context.Context) string
func (TraceContext) LogFieldsFromContext ¶
func (sc TraceContext) LogFieldsFromContext(ctx context.Context) map[string]interface{}
type TraceContextProvider ¶
type TraceContextProvider interface { WithTrace(context.Context, string) context.Context FromContext(context.Context) string ContextCollector }
var DefaultTrace TraceContextProvider = TraceContext{}
type WrappedContext ¶
WrappedContext is both a context and a logger, allowing either syntax log.WithField(ctx, "key", "val").Debug() or ctx = log.WithField(ctx, "key", "val")
func WithFields ¶
func WithFields(ctx context.Context, fields map[string]interface{}) *WrappedContext
func (WrappedContext) Debug ¶
func (ctx WrappedContext) Debug(msg string)
func (WrappedContext) Error ¶
func (ctx WrappedContext) Error(msg string)
func (WrappedContext) Info ¶
func (ctx WrappedContext) Info(msg string)
Click to show internal directories.
Click to hide internal directories.