Initial commit: Эфир мессенджер
This commit is contained in:
40
internal/pkg/logger/logger.go
Normal file
40
internal/pkg/logger/logger.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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...)
|
||||
}
|
||||
Reference in New Issue
Block a user