Show file:line only for debug log level
This commit is contained in:
parent
d6c678b0cd
commit
0b198f71ca
26
main.go
26
main.go
@ -47,6 +47,19 @@ func (loglevel LogLevelFlag) AfterApply() error {
|
|||||||
switch loglevel {
|
switch loglevel {
|
||||||
case "debug":
|
case "debug":
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
|
|
||||||
|
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string {
|
||||||
|
short := file
|
||||||
|
for i := len(file) - 1; i > 0; i-- {
|
||||||
|
if file[i] == '/' {
|
||||||
|
short = file[i+1:]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file = short
|
||||||
|
return file + ":" + strconv.Itoa(line)
|
||||||
|
}
|
||||||
|
log.Logger = log.With().Caller().Logger()
|
||||||
case "info":
|
case "info":
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
case "warn":
|
case "warn":
|
||||||
@ -70,19 +83,6 @@ func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
|
|||||||
func main() {
|
func main() {
|
||||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||||
|
|
||||||
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string {
|
|
||||||
short := file
|
|
||||||
for i := len(file) - 1; i > 0; i-- {
|
|
||||||
if file[i] == '/' {
|
|
||||||
short = file[i+1:]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file = short
|
|
||||||
return file + ":" + strconv.Itoa(line)
|
|
||||||
}
|
|
||||||
log.Logger = log.With().Caller().Logger()
|
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
cli := CLI{}
|
cli := CLI{}
|
||||||
|
Loading…
Reference in New Issue
Block a user