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

Add structured logFormat for text based logging

parent 1395dc01
...@@ -36,6 +36,7 @@ func prepareLoggingFile(logFile string) *reopen.FileWriter { ...@@ -36,6 +36,7 @@ func prepareLoggingFile(logFile string) *reopen.FileWriter {
const ( const (
jsonLogFormat = "json" jsonLogFormat = "json"
textLogFormat = "text" textLogFormat = "text"
structuredFormat = "structured"
noneLogType = "none" noneLogType = "none"
) )
...@@ -69,6 +70,10 @@ func startLogging(config logConfiguration) { ...@@ -69,6 +70,10 @@ func startLogging(config logConfiguration) {
accessLogEntry = accessLogger.WithField("system", "http") accessLogEntry = accessLogger.WithField("system", "http")
log.SetFormatter(&log.TextFormatter{}) log.SetFormatter(&log.TextFormatter{})
case structuredFormat:
formatter := &log.TextFormatter{ForceColors: true, EnvironmentOverrideColors: true}
log.SetFormatter(formatter)
accessLogEntry = log.WithField("system", "http")
default: default:
log.WithField("logFormat", config.logFormat).Fatal("Unknown logFormat configured") log.WithField("logFormat", config.logFormat).Fatal("Unknown logFormat configured")
} }
......
...@@ -59,7 +59,7 @@ var logConfig = logConfiguration{} ...@@ -59,7 +59,7 @@ var logConfig = logConfiguration{}
func init() { func init() {
flag.StringVar(&logConfig.logFile, "logFile", "", "Log file location") 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() { 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