35 lines
480 B
Go
35 lines
480 B
Go
|
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
|
||
|
}
|