From 215dcc8157d104940c88d6075cd7a7eafa0dca1f Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Fri, 20 Apr 2018 17:26:24 +0100 Subject: [PATCH] #3472 add redaction example and snake_case new logging config options (#3484) * Snake case new logging config options and add redaction example * Move warning messages to snake_case too --- base/logger_console.go | 6 +++--- base/logger_file.go | 10 +++++----- base/logging_config.go | 14 +++++++------- examples/basic-couchbase-bucket.json | 2 +- examples/basic-sync-function.json | 2 +- examples/basic-walrus-bucket.json | 2 +- examples/basic-walrus-persisted-bucket.json | 2 +- examples/basic_sg_accel_config.json | 4 ++-- examples/config-dcpshard.json | 2 +- examples/config-server.json | 2 +- examples/cors.json | 2 +- examples/democlusterconfig.json | 4 ++-- examples/events_webhook.json | 4 ++-- examples/logging-with-redaction.json | 14 ++++++++++++++ examples/logging-with-rotation.json | 14 +++++++------- examples/openid-connect.json | 2 +- examples/read-write-timeouts.json | 2 +- examples/replications-in-config.json | 2 +- examples/ssl/ssl.json | 2 +- examples/sync_gateway_with_accel_config.json | 4 ++-- examples/users-roles.json | 2 +- rest/config.go | 10 +++++----- 22 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 examples/logging-with-redaction.json diff --git a/base/logger_console.go b/base/logger_console.go index 5e56d75fd7..81207a8451 100644 --- a/base/logger_console.go +++ b/base/logger_console.go @@ -17,9 +17,9 @@ type ConsoleLogger struct { } type ConsoleLoggerConfig struct { - LogLevel *LogLevel `json:",omitempty"` // Log Level for the console output - LogKeys []string `json:",omitempty"` // Log Keys for the console output - ColorEnabled bool `json:",omitempty"` // Log with color for the console output + LogLevel *LogLevel `json:"log_level,omitempty"` // Log Level for the console output + LogKeys []string `json:"log_keys,omitempty"` // Log Keys for the console output + ColorEnabled bool `json:"color_enabled,omitempty"` // Log with color for the console output Output io.Writer `json:"-"` // Logger output. Defaults to os.Stderr. Can be overridden for testing purposes. } diff --git a/base/logger_file.go b/base/logger_file.go index d8ad1ad018..336f9c7fe2 100644 --- a/base/logger_file.go +++ b/base/logger_file.go @@ -26,16 +26,16 @@ type FileLogger struct { } type FileLoggerConfig struct { - Enabled *bool `json:",omitempty"` // Toggle for this log output - Rotation logRotationConfig `json:",omitempty"` // Log rotation settings + Enabled *bool `json:"enabled,omitempty"` // Toggle for this log output + Rotation logRotationConfig `json:"rotation,omitempty"` // Log rotation settings Output io.Writer `json:"-"` // Logger output. Defaults to os.Stderr. Can be overridden for testing purposes. } type logRotationConfig struct { - MaxSize *int `json:",omitempty"` // The maximum size in MB of the log file before it gets rotated. - MaxAge *int `json:",omitempty"` // The maximum number of days to retain old log files. - LocalTime bool `json:",omitempty"` // If true, it uses the computer's local time to format the backup timestamp. + MaxSize *int `json:"max_size,omitempty"` // The maximum size in MB of the log file before it gets rotated. + MaxAge *int `json:"max_age,omitempty"` // The maximum number of days to retain old log files. + LocalTime bool `json:"localtime,omitempty"` // If true, it uses the computer's local time to format the backup timestamp. } // NewFileLogger returms a new FileLogger from a config. diff --git a/base/logging_config.go b/base/logging_config.go index 22445ce7de..52ee0b0c67 100644 --- a/base/logging_config.go +++ b/base/logging_config.go @@ -14,13 +14,13 @@ const ( ) type LoggingConfig struct { - LogFilePath string `json:",omitempty"` // Absolute or relative path on the filesystem to the log file directory. A relative path is from the directory that contains the Sync Gateway executable file. - RedactionLevel RedactionLevel `json:",omitempty"` - Console ConsoleLoggerConfig `json:",omitempty"` // Console Output - Error FileLoggerConfig `json:",omitempty"` // Error log file output - Warn FileLoggerConfig `json:",omitempty"` // Warn log file output - Info FileLoggerConfig `json:",omitempty"` // Info log file output - Debug FileLoggerConfig `json:",omitempty"` // Debug log file output + LogFilePath string `json:"log_file_path,omitempty"` // Absolute or relative path on the filesystem to the log file directory. A relative path is from the directory that contains the Sync Gateway executable file. + RedactionLevel RedactionLevel `json:"redaction_level,omitempty"` // Redaction level to apply to log output. + Console ConsoleLoggerConfig `json:"console,omitempty"` // Console output + Error FileLoggerConfig `json:"error,omitempty"` // Error log file output + Warn FileLoggerConfig `json:"warn,omitempty"` // Warn log file output + Info FileLoggerConfig `json:"info,omitempty"` // Info log file output + Debug FileLoggerConfig `json:"debug,omitempty"` // Debug log file output DeprecatedDefaultLog *LogAppenderConfig `json:"default,omitempty"` // Deprecated "default" logging option. } diff --git a/examples/basic-couchbase-bucket.json b/examples/basic-couchbase-bucket.json index d3583c07ea..6f9fcc83dd 100644 --- a/examples/basic-couchbase-bucket.json +++ b/examples/basic-couchbase-bucket.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/basic-sync-function.json b/examples/basic-sync-function.json index 182f874ae6..426647e215 100644 --- a/examples/basic-sync-function.json +++ b/examples/basic-sync-function.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/basic-walrus-bucket.json b/examples/basic-walrus-bucket.json index b179862f98..1f0a8e17a5 100644 --- a/examples/basic-walrus-bucket.json +++ b/examples/basic-walrus-bucket.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/basic-walrus-persisted-bucket.json b/examples/basic-walrus-persisted-bucket.json index 47ddd2c10e..7eb2cbc623 100644 --- a/examples/basic-walrus-persisted-bucket.json +++ b/examples/basic-walrus-persisted-bucket.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/basic_sg_accel_config.json b/examples/basic_sg_accel_config.json index 9d49ae47af..da6a015075 100644 --- a/examples/basic_sg_accel_config.json +++ b/examples/basic_sg_accel_config.json @@ -1,8 +1,8 @@ { "logging": { "console": { - "logLevel": "debug", - "logKeys": ["HTTP"] + "log_level": "debug", + "log_keys": ["HTTP"] } }, "adminInterface": "127.0.0.1:4985", diff --git a/examples/config-dcpshard.json b/examples/config-dcpshard.json index 4707c6cf81..fd9051e80f 100644 --- a/examples/config-dcpshard.json +++ b/examples/config-dcpshard.json @@ -3,7 +3,7 @@ "adminInterface":":4985", "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "verbose":"true", diff --git a/examples/config-server.json b/examples/config-server.json index 701a67f9d2..0b8f4b6cdb 100644 --- a/examples/config-server.json +++ b/examples/config-server.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "configServer": "http://localhost:8001/", diff --git a/examples/cors.json b/examples/cors.json index 7a8eb29d22..e403bfb0ec 100644 --- a/examples/cors.json +++ b/examples/cors.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "CORS": { diff --git a/examples/democlusterconfig.json b/examples/democlusterconfig.json index fb251dc2f0..35e45a9a3f 100644 --- a/examples/democlusterconfig.json +++ b/examples/democlusterconfig.json @@ -1,8 +1,8 @@ { "logging": { "console": { - "logLevel": "debug", - "logKeys": ["REST", "Shadow", "CRUD", "HTTP","Access", "Changes", "Auth", "SSL"] + "log_level": "debug", + "log_keys": ["REST", "Shadow", "CRUD", "HTTP","Access", "Changes", "Auth", "SSL"] } }, "maxFileDescriptors": 50000, diff --git a/examples/events_webhook.json b/examples/events_webhook.json index 2047bdd5f1..6f70702f89 100644 --- a/examples/events_webhook.json +++ b/examples/events_webhook.json @@ -1,8 +1,8 @@ { "logging": { "console": { - "logLevel": "debug", - "logKeys": ["CRUD", "Events"] + "log_level": "debug", + "log_keys": ["CRUD", "Events"] } }, "databases": { diff --git a/examples/logging-with-redaction.json b/examples/logging-with-redaction.json new file mode 100644 index 0000000000..d199213223 --- /dev/null +++ b/examples/logging-with-redaction.json @@ -0,0 +1,14 @@ +{ + "logging": { + "redaction_level": "partial" + }, + "databases": { + "db": { + "server": "walrus:data", + "bucket": "default", + "users": {"GUEST": {"disabled": false,"admina_channels": ["*"]}}, + "allow_conflicts": false, + "revs_limit": 20 + } + } +} diff --git a/examples/logging-with-rotation.json b/examples/logging-with-rotation.json index 2f45530b4b..b9cb750095 100644 --- a/examples/logging-with-rotation.json +++ b/examples/logging-with-rotation.json @@ -1,22 +1,22 @@ { "logging": { - "logFilePath": "/var/tmp/sglogs", + "log_file_path": "/var/tmp/sglogs", "console": { - "logLevel": "debug", - "logKeys": ["*"] + "log_level": "debug", + "log_keys": ["*"] }, "error": { "enabled": true, "rotation": { - "maxsize": 20, - "maxage": 180 + "max_size": 20, + "max_age": 180 } }, "warn": { "enabled": true, "rotation": { - "maxsize": 20, - "maxage": 90 + "max_size": 20, + "max_age": 90 } }, "info": { diff --git a/examples/openid-connect.json b/examples/openid-connect.json index d4cbe8154d..f9c4742ac4 100644 --- a/examples/openid-connect.json +++ b/examples/openid-connect.json @@ -2,7 +2,7 @@ "interface":":4984", "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/read-write-timeouts.json b/examples/read-write-timeouts.json index cf622f80a1..4438296b0c 100644 --- a/examples/read-write-timeouts.json +++ b/examples/read-write-timeouts.json @@ -3,7 +3,7 @@ "ServerWriteTimeout": 200, "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/replications-in-config.json b/examples/replications-in-config.json index a0411e426f..67666c7383 100644 --- a/examples/replications-in-config.json +++ b/examples/replications-in-config.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/examples/ssl/ssl.json b/examples/ssl/ssl.json index 23bf4a3ca8..c085becd61 100644 --- a/examples/ssl/ssl.json +++ b/examples/ssl/ssl.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "SSLCert": "examples/ssl/cert.pem", diff --git a/examples/sync_gateway_with_accel_config.json b/examples/sync_gateway_with_accel_config.json index 377aad14fd..cded3ce80d 100644 --- a/examples/sync_gateway_with_accel_config.json +++ b/examples/sync_gateway_with_accel_config.json @@ -1,8 +1,8 @@ { "logging": { "console": { - "logLevel": "debug", - "logKeys": ["HTTP"] + "log_level": "debug", + "log_keys": ["HTTP"] } }, "adminInterface": "127.0.0.1:4985", diff --git a/examples/users-roles.json b/examples/users-roles.json index 116bc4b3ff..b15a8750c2 100644 --- a/examples/users-roles.json +++ b/examples/users-roles.json @@ -1,7 +1,7 @@ { "logging": { "console": { - "logKeys": ["*"] + "log_keys": ["*"] } }, "databases": { diff --git a/rest/config.go b/rest/config.go index 95f1d5e832..b70399cd71 100644 --- a/rest/config.go +++ b/rest/config.go @@ -578,33 +578,33 @@ func (config *ServerConfig) deprecatedConfigLoggingFallback(verbose bool) { if config.Logging.DeprecatedDefaultLog != nil { // Fall back to the old logging.["default"].LogFilePath option if config.Logging.LogFilePath == "" && config.Logging.DeprecatedDefaultLog.LogFilePath != nil { - base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogFilePath. Use logging.logFilePath instead.") + base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogFilePath. Use logging.log_file_path instead.") // Set the new LogFilePath to be the directory containing the old logfile, instead of the full path. config.Logging.LogFilePath = filepath.Dir(*config.Logging.DeprecatedDefaultLog.LogFilePath) } // Fall back to the old logging.["default"].LogKeys option if len(config.Logging.Console.LogKeys) == 0 && len(config.Logging.DeprecatedDefaultLog.LogKeys) > 0 { - base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogKeys. Use logging.console.logKeys instead.") + base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogKeys. Use logging.console.log_keys instead.") config.Logging.Console.LogKeys = config.Logging.DeprecatedDefaultLog.LogKeys } // Fall back to the old logging.["default"].LogLevel option if config.Logging.Console.LogLevel == nil && config.Logging.DeprecatedDefaultLog.LogLevel != 0 { - base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogLevel. Use logging.console.logLevel instead.") + base.Warnf(base.KeyAll, "Using deprecated config option: logging.[\"default\"].LogLevel. Use logging.console.log_level instead.") config.Logging.Console.LogLevel = base.ToLogLevel(config.Logging.DeprecatedDefaultLog.LogLevel) } } // Fall back to the old LogFilePath option if config.Logging.LogFilePath == "" && config.DeprecatedLogFilePath != nil { - base.Warnf(base.KeyAll, "Using deprecated config option: logFilePath. Use logging.logFilePath instead.") + base.Warnf(base.KeyAll, "Using deprecated config option: logFilePath. Use logging.log_file_path instead.") config.Logging.LogFilePath = *config.DeprecatedLogFilePath } // Fall back to the old Log option if config.Logging.Console.LogKeys == nil && len(config.DeprecatedLog) > 0 { - base.Warnf(base.KeyAll, "Using deprecated config option: log. Use logging.console.logKeys instead.") + base.Warnf(base.KeyAll, "Using deprecated config option: log. Use logging.console.log_keys instead.") config.Logging.Console.LogKeys = config.DeprecatedLog }