logger

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLevelFromEnv

func GetLevelFromEnv() slog.Level

GetLevelFromEnv

This function reads the LOG_LEVEL environment variable and returns the corresponding slog.Level. If the LOG_LEVEL environment variable is not set, it returns slog.LevelInfo.

Returns:

  • The slog.Level corresponding to the LOG_LEVEL environment variable.

Example:

level := GetLevelFromEnv()

Types

type Log

type Log interface {
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	Debug(msg string, args ...any)
}

Log is an interface that defines the methods for logging.

The methods are used to log messages at different levels. The levels are Info, Warn, Error, and Debug.

Example:

logger := logger.NewLogger()
logger.Info("This is an info message")
logger.Warn("This is a warning message")
logger.Error("This is an error message")
logger.Debug("This is a debug message")

type SlogAdapter

type SlogAdapter struct {
	Logger Log
}

SlogAdapter is a struct that implements the Log interface.

It contains a slog.Logger instance. The slog.Logger instance is used for logging.

func NewLogger

func NewLogger() *SlogAdapter

NewLogger creates a new SlogAdapter instance with a slog.Logger.

It reads the LOG_FORMAT environment variable to determine the log format (text or json). If the LOG_FORMAT environment variable is not set, it defaults to text.

Returns:

  • A new SlogAdapter instance with a slog.Logger.

Example:

logger := logger.NewLogger()
logger.Info("This is an info message")
logger.Warn("This is a warning message")
logger.Error("This is an error message")
logger.Debug("This is a debug message")

Jump to

Keyboard shortcuts

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