well-goknown/vendor/git.devvul.com/asara/gologger/gologger.go
2024-09-23 20:35:59 -04:00

47 lines
807 B
Go

package gologger
import (
"fmt"
"io"
"os"
"runtime"
"strings"
"sync"
"time"
"github.com/rs/zerolog"
)
var once sync.Once
var log zerolog.Logger
func Get(l string) zerolog.Logger {
once.Do(func() {
zerolog.TimeFieldFormat = time.RFC3339Nano
var output io.Writer = zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
FormatCaller: func(i interface{}) string {
_, vpath, _, _ := runtime.Caller(0)
bpath, _, _ := strings.Cut(vpath, "vendor/")
_, ret, _ := strings.Cut(fmt.Sprintf("%s", i), bpath)
return ret
},
}
level, err := zerolog.ParseLevel(l)
if err != nil {
panic("unable to get parse level for logger")
}
log = zerolog.New(output).
Level(zerolog.Level(level)).
With().
Timestamp().
Logger()
})
return log
}