image-storage/config/logging.go

36 lines
598 B
Go
Raw Permalink Normal View History

2025-10-20 18:23:53 +03:00
package config
import (
"fmt"
log "github.com/sirupsen/logrus"
"os"
"path"
"runtime"
)
func LogSetup(lvl string) {
l, err := log.ParseLevel(lvl)
if err != nil {
log.SetLevel(log.DebugLevel)
}
log.SetFormatter(
&log.TextFormatter{
FullTimestamp: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := path.Base(f.File)
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf(" %s:%d", filename, f.Line)
},
},
)
if l == log.DebugLevel {
log.SetLevel(l)
log.SetReportCaller(true)
} else {
log.SetLevel(l)
}
log.SetOutput(os.Stdout)
}