mirror of
https://github.com/containrrr/watchtower.git
synced 2026-03-16 09:16:30 +01:00
feat: allow logging output to use JSON formatter
Signed-off-by: GridexX <arsene582@gmail.com>
This commit is contained in:
parent
a5d7f23d2e
commit
be98119552
4 changed files with 56 additions and 11 deletions
|
|
@ -86,6 +86,12 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
|
|||
viper.GetBool("WATCHTOWER_LABEL_ENABLE"),
|
||||
"Watch containers where the com.centurylinklabs.watchtower.enable label is true")
|
||||
|
||||
flags.BoolP(
|
||||
"json-logging",
|
||||
"j",
|
||||
viper.GetBool("WATCHTOWER_JSON_LOGGING"),
|
||||
"Enables the JSON log formatter for logging")
|
||||
|
||||
flags.BoolP(
|
||||
"debug",
|
||||
"d",
|
||||
|
|
|
|||
|
|
@ -183,6 +183,28 @@ func TestProcessFlagAliasesLogLevelFromEnvironment(t *testing.T) {
|
|||
assert.Equal(t, `debug`, logLevel)
|
||||
}
|
||||
|
||||
func TestJSONLoggingFlag(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
|
||||
SetDefaults()
|
||||
RegisterDockerFlags(cmd)
|
||||
RegisterSystemFlags(cmd)
|
||||
|
||||
// Ensure the default value is false
|
||||
enableJsonFormatter, err := cmd.PersistentFlags().GetBool("json-logging")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, false, enableJsonFormatter)
|
||||
|
||||
// Test with the argument
|
||||
require.NoError(t, cmd.ParseFlags([]string{`--json-logging`}))
|
||||
flags := cmd.Flags()
|
||||
enableJsonFormatter, _ = flags.GetBool("json-logging")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, enableJsonFormatter)
|
||||
|
||||
}
|
||||
|
||||
func TestProcessFlagAliasesSchedAndInterval(t *testing.T) {
|
||||
logrus.StandardLogger().ExitFunc = func(_ int) { panic(`FATAL`) }
|
||||
cmd := new(cobra.Command)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue