gologger/gologger.go

35 lines
480 B
Go
Raw Permalink Normal View History

2023-08-03 17:45:40 +00:00
package gologger
import (
"io"
"os"
"sync"
"time"
"github.com/rs/zerolog"
)
var once sync.Once
var log zerolog.Logger
func Get(c string, l int) zerolog.Logger {
once.Do(func() {
zerolog.TimeFieldFormat = time.RFC3339Nano
var output io.Writer = zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
}
log = zerolog.New(output).
Level(zerolog.Level(l)).
With().
Str("context", c).
Timestamp().
Logger()
})
return log
}