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 ¶
- func InjectRootAttrs(h slog.Handler, cfg config.LoggerConfig) slog.Handler
- func NewJSONLogHandler(level slog.Level) slog.Handler
- func NewTracingHandler(level slog.Level) slogmulti.Middleware
- func ParseLogLevel(level string) slog.Level
- type TracingHandler
- func (h *TracingHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *TracingHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *TracingHandler) Handler() slog.Handler
- func (h *TracingHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *TracingHandler) WithGroup(name string) slog.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectRootAttrs ¶
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 ¶
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 ¶
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 ¶
Enabled returns true if the log level is greater than or equal to the handler's level
func (*TracingHandler) Handle ¶
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