Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Call Site #2909

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions internal/common/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"net/http"
"os"
"path"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -80,6 +83,7 @@ func ConfigureCommandLineLogging() {
func ConfigureLogging() {
log.SetLevel(readEnvironmentLogLevel())
log.SetFormatter(readEnvironmentLogFormat())
log.SetReportCaller(true)
log.SetOutput(os.Stdout)
}

Expand All @@ -99,16 +103,29 @@ func readEnvironmentLogFormat() log.Formatter {
if !ok {
formatStr = "colourful"
}

textFormatter := &log.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: logTimestampFormat,
CallerPrettyfier: func(frame *runtime.Frame) (function string, file string) {
fileName := path.Base(frame.File) + ":" + strconv.Itoa(frame.Line)
return "", fileName
},
}

switch strings.ToLower(formatStr) {
case "json":
return &log.JSONFormatter{TimestampFormat: logTimestampFormat}
case "colourful":
return &log.TextFormatter{ForceColors: true, FullTimestamp: true, TimestampFormat: logTimestampFormat}
return textFormatter
case "text":
return &log.TextFormatter{DisableColors: true, FullTimestamp: true, TimestampFormat: logTimestampFormat}
textFormatter.ForceColors = false
textFormatter.DisableColors = true
return textFormatter
default:
println(os.Stderr, fmt.Sprintf("Unknown log format %s, defaulting to colourful format", formatStr))
return &log.TextFormatter{ForceColors: true, FullTimestamp: true, TimestampFormat: logTimestampFormat}
return textFormatter
}
}

Expand Down