support JSON output for kolide logs (#1026)

This commit is contained in:
Victor Vrantchan 2017-01-19 09:41:28 -05:00 committed by GitHub
parent d45c0103d1
commit c13b8cc0cf
2 changed files with 14 additions and 7 deletions

View file

@ -47,15 +47,19 @@ binary (which you're executing right now). Use the options below to customize
the way that the kolide server works.
`,
Run: func(cmd *cobra.Command, args []string) {
var (
ctx = context.Background()
logger kitlog.Logger
)
ctx := context.Background()
config := configManager.LoadConfig()
logger = kitlog.NewLogfmtLogger(os.Stderr)
logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC)
var logger kitlog.Logger
{
output := os.Stderr
if config.Logging.JSON {
logger = kitlog.NewJSONLogger(output)
} else {
logger = kitlog.NewLogfmtLogger(output)
}
logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC)
}
var ds kolide.Datastore
var err error

View file

@ -68,6 +68,7 @@ type OsqueryConfig struct {
// LoggingConfig defines configs related to logging
type LoggingConfig struct {
Debug bool
JSON bool
DisableBanner bool
}
@ -129,6 +130,7 @@ func (man Manager) addConfigs() {
// Logging
man.addConfigBool("logging.debug", false)
man.addConfigBool("logging.json", false)
man.addConfigBool("logging.disable_banner", false)
}
@ -177,6 +179,7 @@ func (man Manager) LoadConfig() KolideConfig {
},
Logging: LoggingConfig{
Debug: man.getConfigBool("logging.debug"),
JSON: man.getConfigBool("logging.json"),
DisableBanner: man.getConfigBool("logging.disable_banner"),
},
}