logger

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package logger the internal logger configuration for slog It implements the logger structure as proposed at the FLYR Logging Standards (https://flyrlabs.atlassian.net/wiki/spaces/CE/pages/4323967442/Logging+Standards)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectRootAttrs

func InjectRootAttrs(h slog.Handler, cfg config.LoggerConfig) slog.Handler

InjectRootAttrs adds root attributes to a slog handler.

This function enhances the given slog.Handler with a set of attributes that are common across the application, such as service instance ID, and service version The attributes are being fetched from the environment variable "OTEL_RESOURCE_ATTRIBUTES". The goal is to have a consistent set of attributes across all logs and spans. These attributes are typically added once at the root level and included in all logs generated by the handler. InjectRootAttrs returns a new slog.Handler with the additional attributes applied.

func NewJSONLogHandler

func NewJSONLogHandler(level slog.Level) slog.Handler

NewJSONLogHandler creates a new JSON log handler with custom configurations.

This function initializes a slog.Handler that outputs logs in JSON format to standard output. The handler is setting the log level according to the provided configuration, and replacing certain attributes using the replaceAttributes function for custom formatting.

func NewTracingHandler

func NewTracingHandler(level slog.Level) slogmulti.Middleware

NewTracingHandler creates a new TracingHandler with the specified log level.

This function wraps a given slog.Handler with a TracingHandler, which can be used to add tracing information to log entries. If the provided handler is already a TracingHandler, it extracts the underlying handler to avoid redundant wrapping. The log level is parsed and set to control the tracing output level.

Returns an slogmulti.Middleware

func ParseLogLevel

func ParseLogLevel(level string) slog.Level

parseLogLevel converts a string to a slog.Level.

If the string is not a valid log level, it defaults to info.

Types

type TracingHandler

type TracingHandler struct {
	// contains filtered or unexported fields
}

func (*TracingHandler) Enabled

func (h *TracingHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if the log level is greater than or equal to the handler's level

func (*TracingHandler) Handle

func (h *TracingHandler) Handle(ctx context.Context, record slog.Record) error

Handle adds the trace and span ids to the log record and passes it to the next handler

func (*TracingHandler) Handler

func (h *TracingHandler) Handler() slog.Handler

WithLevel returns a new handler with the given log level

func (*TracingHandler) WithAttrs

func (h *TracingHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes added to the log record

func (*TracingHandler) WithGroup

func (h *TracingHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group name added to the log record

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL