package main import ( "fmt" "os" "strings" "github.com/fatih/color" "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) func setupLog() { // log.Logger = log.With().Caller().Logger() log.Logger = log.Output(zerolog.ConsoleWriter{ Out: os.Stdout, TimeFormat: "2006/01/02 15:04:05", FormatCaller: func(i interface{}) string { var c string if cc, ok := i.(string); ok { c = cc } if len(c) > 0 { // shorten caller to mod/file:line segs := strings.Split(c, ":") file := segs[len(segs)-2] short := file ptr := 0 for i := len(file) - 1; i > 0; i-- { if file[i] == '/' { if ptr == 0 { short = file[i+1:] ptr = i } else { short = fmt.Sprintf("%v/%v", file[i+1:ptr], short) break } } if file[i] == '@' { ptr = i } } return color.GreenString("%v:%v >", short, segs[len(segs)-1]) } return c }, }) zerolog.TimeFieldFormat = zerolog.TimeFormatUnix zerolog.DurationFieldInteger = true zerolog.SetGlobalLevel(-1) }