loggergo

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 7

README

loggergo

GitHub tag (with filter) Go Reference Maintainability

Logging library I've come up with in order unify way my apps implement logging.

diagram

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

This section is empty.

Functions

func LoggerInit

func LoggerInit(ctx context.Context, config Config, additionalAttrs ...any) (*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 struct {
	Level              string     `json:"level"`             // Level specifies the log level. Valid values are "debug", "info", "warn", and "error".
	Format             string     `json:"format"`            // Format specifies the log format. Valid values are "plain" (default), "otel" and "json".
	DevMode            bool       `json:"dev_mode"`          // Dev indicates whether the logger is running in development mode.
	DevFlavor          string     `json:"dev_flavor"`        // DevFlavor specifies the development flavor. Valid values are "tint" (default), slogor and "devslog".
	OutputStream       *os.File   `json:"output_stream"`     // OutputStream specifies the output stream for the logger. Valid values are "stdout" (default) and "stderr".
	OtelTracingEnabled bool       `json:"otel_enabled"`      // OtelTracingEnabled specifies whether OpenTelemetry support is enabled. Default is true.
	OtelLoggerName     string     `json:"otel_logger_name"`  // OtelLoggerName specifies the name of the logger for OpenTelemetry.
	Output             OutputType `json:"output"`            // Output specifies where logs will be sent to. Valid values are "console", "otel" and "fanout" (default) - which is a combination of "console" and "otel".
	OtelServiceName    string     `json:"otel_service_name"` // OtelServiceName specifies the service name for OpenTelemetry.
}

Config represents the configuration options for the LoggerGo logger.

type OutputType added in v1.2.5

type OutputType int

OutputType represents the type of output for the logger.

const (
	// OutputConsole represents console output.
	OutputConsole OutputType = iota
	// OutputOtel represents otel output.
	OutputOtel
	// OutputFanout represents both console and otel output.
	OutputFanout
)

func (OutputType) String added in v1.2.5

func (o OutputType) String() string

Jump to

Keyboard shortcuts

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