Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLevelFromEnv ¶
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")