using JSON logging format for notary server and signer for easier integration with backend metrics platforms

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
David Lawrence 2016-01-06 16:59:20 -08:00
parent cc03297c77
commit b56372a1d8
2 changed files with 19 additions and 1 deletions

View File

@ -28,10 +28,14 @@ import (
)
// DebugAddress is the debug server address to listen on
const DebugAddress = "localhost:8080"
const (
jsonLogFormat = "json"
DebugAddress = "localhost:8080"
)
var (
debug bool
logFormat string
configFile string
envPrefix = "NOTARY_SERVER"
mainViper = viper.New()
@ -42,6 +46,12 @@ func init() {
// Setup flags
flag.StringVar(&configFile, "config", "", "Path to configuration file")
flag.BoolVar(&debug, "debug", false, "Enable the debugging server on localhost:8080")
flag.StringVar(&logFormat, "logf", "json", "Set the format of the logs. Only 'json' and 'logfmt' are supported at the moment.")
// this needs to be in init so that _ALL_ logs are in the correct format
if logFormat == jsonLogFormat {
logrus.SetFormatter(new(logrus.JSONFormatter))
}
}
// get the address for the HTTP server, and parses the optional TLS

View File

@ -37,6 +37,7 @@ import (
)
const (
jsonLogFormat = "json"
debugAddr = "localhost:8080"
envPrefix = "NOTARY_SIGNER"
defaultAliasEnv = "DEFAULT_ALIAS"
@ -44,6 +45,7 @@ const (
var (
debug bool
logFormat string
configFile string
mainViper = viper.New()
)
@ -53,6 +55,12 @@ func init() {
// Setup flags
flag.StringVar(&configFile, "config", "", "Path to configuration file")
flag.BoolVar(&debug, "debug", false, "show the version and exit")
flag.StringVar(&logFormat, "logf", "json", "Set the format of the logs. Only 'json' and 'logfmt' are supported at the moment.")
// this needs to be in init so that _ALL_ logs are in the correct format
if logFormat == jsonLogFormat {
logrus.SetFormatter(new(logrus.JSONFormatter))
}
}
func passphraseRetriever(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error) {