loggergo

package module
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 8

README

LoggerGo

GitHub tag (with filter) Go Reference Maintainability

A lightweight, customizable logging library for Go, designed to provide flexible and simple logging capabilities.

diagram

Features

  • Simple API for various log levels (Info, Debug, Error).
  • Customizable log formats and outputs.
  • Lightweight and easy to integrate.
  • Supports OTEL (OpenTelemetry) by injecting spanID & traceID into logs.
  • By default registers as slog.Default() but this can be change via option

Installation

To install LoggerGo, run:

go get github.com/wasilak/loggergo

Usage

Here's a basic example of how to use LoggerGo:

https://github.com/wasilak/loggergo/blob/main/examples/simple/main.go

Contributing

Contributions are welcome! Please fork the repository, make changes, and submit a pull request.

Documentation

Overview

Package loggergo provides functionality for configuring and setting up different logging modes in Go applications. It includes support for OpenTelemetry format, JSON format, and plain format with different flavors. The package also supports enabling OpenTelemetry tracing for the logs.

Index

Constants

This section is empty.

Variables

View Source
var Types = struct {
	AllDevFlavors       func() []types.DevFlavor
	DevFlavorFromString func(string) types.DevFlavor
	DevFlavorTint       types.DevFlavor
	DevFlavorSlogor     types.DevFlavor
	DevFlavorDevslog    types.DevFlavor

	AllLogFormats       func() []types.LogFormat
	LogFormatFromString func(string) types.LogFormat
	LogFormatText       types.LogFormat
	LogFormatJSON       types.LogFormat
	LogFormatOtel       types.LogFormat

	AllLogLevels       func() []slog.Level
	LogLevelFromString func(string) slog.Level

	AllOutputTypes       func() []types.OutputType
	OutputTypeFromString func(string) types.OutputType
	OutputConsole        types.OutputType
	OutputOtel           types.OutputType
	OutputFanout         types.OutputType
}{
	AllDevFlavors:       types.AllDevFlavors,
	DevFlavorFromString: types.DevFlavorFromString,
	DevFlavorTint:       types.DevFlavorTint,
	DevFlavorSlogor:     types.DevFlavorSlogor,
	DevFlavorDevslog:    types.DevFlavorDevslog,

	AllLogFormats:       types.AllLogFormats,
	LogFormatFromString: types.LogFormatFromString,
	LogFormatText:       types.LogFormatText,
	LogFormatJSON:       types.LogFormatJSON,
	LogFormatOtel:       types.LogFormatOtel,

	AllLogLevels:       types.AllLogLevels,
	LogLevelFromString: types.LogLevelFromString,

	AllOutputTypes:       types.AllOutputTypes,
	OutputTypeFromString: types.OutputTypeFromString,
	OutputConsole:        types.OutputConsole,
	OutputOtel:           types.OutputOtel,
	OutputFanout:         types.OutputFanout,
}

Functions

func GetLogLevelAccessor added in v1.5.5

func GetLogLevelAccessor() *slog.LevelVar

func Init added in v1.6.0

func Init(ctx context.Context, config types.Config, additionalAttrs ...any) (context.Context, *slog.Logger, error)

The LoggerInit function initializes a logger with the provided configuration and additional attributes.

Types

type Config added in v1.2.4

type Config = types.Config

expose the types for external usage

type CustomContextAttributeHandler added in v1.6.0

type CustomContextAttributeHandler struct {
	ContextKeysDefault interface{}
	// contains filtered or unexported fields
}

CustomContextAttributeHandler wraps an existing handler and adds a custom attribute to all logs.

func NewCustomContextAttributeHandler added in v1.6.0

func NewCustomContextAttributeHandler(handler slog.Handler, keys []interface{}, contextKeysDefault interface{}) *CustomContextAttributeHandler

NewCustomContextAttributeHandler creates a new handler that wraps the given handler and adds a custom attribute.

func (*CustomContextAttributeHandler) Enabled added in v1.6.0

Enabled delegates the Enabled check to the inner handler.

func (*CustomContextAttributeHandler) Handle added in v1.6.0

Handle adds the custom attribute and delegates the log processing to the inner handler.

func (*CustomContextAttributeHandler) WithAttrs added in v1.6.0

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

WithAttrs creates a new handler with additional attributes, preserving the custom attribute.

func (*CustomContextAttributeHandler) WithGroup added in v1.6.0

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

WithGroup creates a new handler with a group, preserving the custom attribute.

Directories

Path Synopsis
examples
lib

Jump to

Keyboard shortcuts

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