sshpoke/internal/logger/logger.go

29 lines
536 B
Go
Raw Normal View History

2023-11-16 20:09:40 +03:00
package logger
import (
"github.com/Neur0toxine/sshpoke/internal/config"
"go.uber.org/zap"
)
var (
Default *zap.Logger
Sugar *zap.SugaredLogger
)
func Initialize() {
2023-11-17 20:39:00 +03:00
Default = New(config.Default.Debug)
2023-11-16 20:09:40 +03:00
Sugar = Default.Sugar()
}
func New(debug bool) *zap.Logger {
2023-11-17 20:39:00 +03:00
zapConfig := zap.NewProductionConfig()
2023-11-16 20:09:40 +03:00
if debug {
2023-11-17 20:39:00 +03:00
zapConfig = zap.NewDevelopmentConfig()
2023-11-16 20:09:40 +03:00
}
zapConfig.Encoding = "console"
2023-11-17 20:39:00 +03:00
zapConfig.EncoderConfig.CallerKey = ""
zapConfig.EncoderConfig.EncodeCaller = nil
2023-11-16 20:09:40 +03:00
logger, _ := zapConfig.Build()
return logger
}