Documentation ¶
Overview ¶
nolint: sloglint
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func Fatal(msg string, args ...any)
- func FatalContext(ctx context.Context, msg string, args ...any)
- func FromContext(ctx context.Context) *slog.Logger
- func GCPAttrReplacer(groups []string, attr slog.Attr) slog.Attr
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func Init(cfg Config) error
- func Log(level slog.Level, msg string, args ...any)
- func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
- func LogContext(ctx context.Context, level slog.Level, msg string, args ...any)
- func NewContext(ctx context.Context, log *slog.Logger) context.Context
- func NewGCPHandler(opts *slog.HandlerOptions) slog.Handler
- func Panic(msg string, args ...any)
- func PanicContext(ctx context.Context, msg string, args ...any)
- func SetLevel(level slog.Level) (old slog.Level)
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- func With(args ...any) *slog.Logger
- func WithContext(ctx context.Context, args ...any) context.Context
- func WithGroup(group string) *slog.Logger
- func WithGroupContext(ctx context.Context, group string) context.Context
- type Config
Constants ¶
const ( LevelCritical = slog.Level(12) LevelPanic = slog.Level(14) LevelFatal = slog.Level(16) )
const ( // DefaultLevel is the default minimum reporting level for the logger DefaultLevel = slog.LevelDebug )
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶
DebugContext logs at [LevelDebug] from logger in the given context.
func ErrorContext ¶
ErrorContext logs at [LevelError] from logger in the given context.
func Fatal ¶
Fatal logs at LevelFatal followed by a call to os.Exit(1).
func FatalContext ¶
FatalContext logs at LevelFatal and then os.Exit(1) from logger in the given context.
func FromContext ¶
FromContext returns the logger from the context. If no logger is found, a new
func GCPAttrReplacer ¶
GCPAttrReplacer replaces the default attribute keys with the GCP logging attribute keys.
func InfoContext ¶
InfoContext logs at [LevelInfo] from logger in the given context.
func Log ¶
Log emits a log record with the current time and the given level and message. The Record's Attrs consist of the Logger's attributes followed by the Attrs specified by args.
func LogContext ¶
LogContext logs at the given level from logger in the given context.
func NewContext ¶
NewContext returns a new context with logger attached.
func NewGCPHandler ¶
func NewGCPHandler(opts *slog.HandlerOptions) slog.Handler
NewGCPHandler returns a new GCP handler. The handler writes logs to the os.Stdout and replaces the default attribute keys/values with the GCP logging attribute keys/values
https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
func PanicContext ¶
PanicContext logs at LevelPanic and then panics from logger in the given context.
func WarnContext ¶
WarnContext logs at [LevelWarn] from logger in the given context.
func With ¶
With returns a Logger that includes the given attributes in each output operation. Arguments are converted to attributes as if by [Logger.Log].
func WithContext ¶
WithContext returns a new context with given logger attributes.
func WithGroup ¶
WithGroup returns a Logger that starts a group, if name is non-empty. The keys of all attributes added to the Logger will be qualified by the given name. (How that qualification happens depends on the [Handler.WithGroup] method of the Logger's Handler.)
If name is empty, WithGroup returns the receiver.
Types ¶
type Config ¶
type Config struct { // Output is the logger output format. // Possible values: // - Text (default) // - JSON // - GCP: Output format for Stackdriver Logging/Cloud Logging or others GCP services. Output string `mapstructure:"output" env:"OUTPUT" envDefault:"text"` // Debug is enabled logger level debug. (default: false) Debug bool `mapstructure:"debug" env:"DEBUG" envDefault:"false"` }
Config is the logger configuration.