Commit 9ef6b2c8 authored by Alessio Caiazza's avatar Alessio Caiazza

Add structured logFormat for text based logging

parent 1395dc01
......@@ -34,9 +34,10 @@ func prepareLoggingFile(logFile string) *reopen.FileWriter {
}
const (
jsonLogFormat = "json"
textLogFormat = "text"
noneLogType = "none"
jsonLogFormat = "json"
textLogFormat = "text"
structuredFormat = "structured"
noneLogType = "none"
)
type logConfiguration struct {
......@@ -69,6 +70,10 @@ func startLogging(config logConfiguration) {
accessLogEntry = accessLogger.WithField("system", "http")
log.SetFormatter(&log.TextFormatter{})
case structuredFormat:
formatter := &log.TextFormatter{ForceColors: true, EnvironmentOverrideColors: true}
log.SetFormatter(formatter)
accessLogEntry = log.WithField("system", "http")
default:
log.WithField("logFormat", config.logFormat).Fatal("Unknown logFormat configured")
}
......
......@@ -59,7 +59,7 @@ var logConfig = logConfiguration{}
func init() {
flag.StringVar(&logConfig.logFile, "logFile", "", "Log file location")
flag.StringVar(&logConfig.logFormat, "logFormat", "text", "Log format to use defaults to text (text, json, none)")
flag.StringVar(&logConfig.logFormat, "logFormat", "text", "Log format to use defaults to text (text, json, structured, none)")
}
func main() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment