well-goknown/logger/logger.go
2023-04-29 14:01:40 -04:00

41 lines
642 B
Go

package logger
import (
"io"
"os"
"strconv"
"sync"
"time"
"git.minhas.io/asara/well-goknown/config"
"github.com/rs/zerolog"
)
var once sync.Once
var log zerolog.Logger
func Get() zerolog.Logger {
once.Do(func() {
zerolog.TimeFieldFormat = time.RFC3339Nano
logLevel, err := strconv.Atoi(config.GetConfig().LogLevel)
if err != nil {
logLevel = int(zerolog.InfoLevel) // default to INFO
}
var output io.Writer = zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
}
log = zerolog.New(output).
Level(zerolog.Level(logLevel)).
With().
Timestamp().
Logger()
})
return log
}