Documentation
¶
Index ¶
- func Debug(ctx context.Context, msg string)
- func Error(ctx context.Context, err error)
- func Errorf(ctx context.Context, format string, args ...any)
- func Info(ctx context.Context, msg string)
- func SetDefault(logger Logger)
- func Warn(ctx context.Context, err error)
- func Warnf(ctx context.Context, format string, args ...any)
- func WithContext(ctx context.Context, logger Logger) context.Context
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶ added in v1.2.0
Errorf logs an error as error level using Logger obtained from FromContext.
func SetDefault ¶
func SetDefault(logger Logger)
SetDefault makes Default return the specified Logger.
If the given Logger is nil, this function triggers a panic.
Types ¶
type Logger ¶
type Logger interface {
// Debug logs a message as debug level.
Debug(ctx context.Context, msg string)
// Info logs a message as info level.
Info(ctx context.Context, msg string)
// Warn logs an error as warn level.
Warn(ctx context.Context, err error)
// Warnf logs an error as warn level.
Warnf(ctx context.Context, format string, args ...any)
// Error logs an error as error level.
Error(ctx context.Context, err error)
// Errorf logs an error as error level.
Errorf(ctx context.Context, format string, args ...any)
}
Logger includes functions to log messages or errors.
func Default ¶
func Default() Logger
Default returns a Logger set by SetDefault, or default Logger instance that uses slog.Default.
func FromContext ¶
FromContext takes the Logger from context.Context.
If the given context.Context does not have the Logger, this function returns Default.
func NewLoggerWithSlog ¶
NewLoggerWithSlog creates Logger using slog.Logger.
func NewLoggerWithWriter ¶ added in v1.1.0
NewLoggerWithWriter creates a Logger that writes to the given io.Writer.
func NewStderrLogger ¶ added in v1.1.0
NewStderrLogger creates a Logger that writes to os.Stderr.
func NewStdoutLogger ¶ added in v1.1.0
NewStdoutLogger creates a Logger that writes to os.Stdout.