40 lines
676 B
Go
40 lines
676 B
Go
|
|
package logger
|
||
|
|
|
||
|
|
import (
|
||
|
|
"log/slog"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
var Log *slog.Logger
|
||
|
|
|
||
|
|
func Init(environment string) {
|
||
|
|
var handler slog.Handler
|
||
|
|
if environment == "production" {
|
||
|
|
handler = slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||
|
|
Level: slog.LevelInfo,
|
||
|
|
})
|
||
|
|
} else {
|
||
|
|
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||
|
|
Level: slog.LevelDebug,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
Log = slog.New(handler)
|
||
|
|
slog.SetDefault(Log)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Info(msg string, args ...any) {
|
||
|
|
Log.Info(msg, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Debug(msg string, args ...any) {
|
||
|
|
Log.Debug(msg, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Error(msg string, args ...any) {
|
||
|
|
Log.Error(msg, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Warn(msg string, args ...any) {
|
||
|
|
Log.Warn(msg, args...)
|
||
|
|
}
|