chore(message): Add option to redact contents of messages in logs (#719)
This commit is contained in:
parent
131e8a156b
commit
a35fc9fbd2
|
@ -179,6 +179,7 @@ log:
|
||||||
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
||||||
error_level: "error"
|
error_level: "error"
|
||||||
hide_token: true
|
hide_token: true
|
||||||
|
hide_messages: false
|
||||||
|
|
||||||
stat:
|
stat:
|
||||||
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
||||||
|
|
|
@ -98,6 +98,7 @@ log:
|
||||||
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
||||||
error_level: "error"
|
error_level: "error"
|
||||||
hide_token: true
|
hide_token: true
|
||||||
|
hide_messages: false
|
||||||
|
|
||||||
stat:
|
stat:
|
||||||
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
||||||
|
@ -208,6 +209,7 @@ type SectionLog struct {
|
||||||
ErrorLog string `yaml:"error_log"`
|
ErrorLog string `yaml:"error_log"`
|
||||||
ErrorLevel string `yaml:"error_level"`
|
ErrorLevel string `yaml:"error_level"`
|
||||||
HideToken bool `yaml:"hide_token"`
|
HideToken bool `yaml:"hide_token"`
|
||||||
|
HideMessages bool `yaml:"hide_messages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SectionStat is sub section of config.
|
// SectionStat is sub section of config.
|
||||||
|
@ -397,6 +399,7 @@ func LoadConf(confPath ...string) (*ConfYaml, error) {
|
||||||
conf.Log.ErrorLog = viper.GetString("log.error_log")
|
conf.Log.ErrorLog = viper.GetString("log.error_log")
|
||||||
conf.Log.ErrorLevel = viper.GetString("log.error_level")
|
conf.Log.ErrorLevel = viper.GetString("log.error_level")
|
||||||
conf.Log.HideToken = viper.GetBool("log.hide_token")
|
conf.Log.HideToken = viper.GetBool("log.hide_token")
|
||||||
|
conf.Log.HideMessages = viper.GetBool("log.hide_messages")
|
||||||
|
|
||||||
// Queue Engine
|
// Queue Engine
|
||||||
conf.Queue.Engine = viper.GetString("queue.engine")
|
conf.Queue.Engine = viper.GetString("queue.engine")
|
||||||
|
|
|
@ -119,6 +119,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
assert.Equal(suite.T(), "stderr", suite.ConfGorushDefault.Log.ErrorLog)
|
assert.Equal(suite.T(), "stderr", suite.ConfGorushDefault.Log.ErrorLog)
|
||||||
assert.Equal(suite.T(), "error", suite.ConfGorushDefault.Log.ErrorLevel)
|
assert.Equal(suite.T(), "error", suite.ConfGorushDefault.Log.ErrorLevel)
|
||||||
assert.Equal(suite.T(), true, suite.ConfGorushDefault.Log.HideToken)
|
assert.Equal(suite.T(), true, suite.ConfGorushDefault.Log.HideToken)
|
||||||
|
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Log.HideMessages)
|
||||||
|
|
||||||
assert.Equal(suite.T(), "memory", suite.ConfGorushDefault.Stat.Engine)
|
assert.Equal(suite.T(), "memory", suite.ConfGorushDefault.Stat.Engine)
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Stat.Redis.Cluster)
|
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Stat.Redis.Cluster)
|
||||||
|
|
|
@ -84,6 +84,7 @@ log:
|
||||||
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
||||||
error_level: "error"
|
error_level: "error"
|
||||||
hide_token: true
|
hide_token: true
|
||||||
|
hide_messages: false
|
||||||
|
|
||||||
stat:
|
stat:
|
||||||
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
||||||
|
|
|
@ -175,12 +175,17 @@ func GetLogPushEntry(input *InputLog) LogPushEntry {
|
||||||
token = hideToken(input.Token, 10)
|
token = hideToken(input.Token, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message := input.Message
|
||||||
|
if input.HideMessage {
|
||||||
|
message = "(message redacted)"
|
||||||
|
}
|
||||||
|
|
||||||
return LogPushEntry{
|
return LogPushEntry{
|
||||||
ID: input.ID,
|
ID: input.ID,
|
||||||
Type: input.Status,
|
Type: input.Status,
|
||||||
Platform: plat,
|
Platform: plat,
|
||||||
Token: token,
|
Token: token,
|
||||||
Message: input.Message,
|
Message: message,
|
||||||
Error: errMsg,
|
Error: errMsg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +199,7 @@ type InputLog struct {
|
||||||
Platform int
|
Platform int
|
||||||
Error error
|
Error error
|
||||||
HideToken bool
|
HideToken bool
|
||||||
|
HideMessage bool
|
||||||
Format string
|
Format string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,10 @@ func TestLogPushEntry(t *testing.T) {
|
||||||
in.Token = "1234567890"
|
in.Token = "1234567890"
|
||||||
in.HideToken = true
|
in.HideToken = true
|
||||||
assert.Equal(t, "**********", GetLogPushEntry(&in).Token)
|
assert.Equal(t, "**********", GetLogPushEntry(&in).Token)
|
||||||
|
|
||||||
|
in.Message = "hellothisisamessage"
|
||||||
|
in.HideMessage = true
|
||||||
|
assert.Equal(t, "(message redacted)", GetLogPushEntry(&in).Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogPush(t *testing.T) {
|
func TestLogPush(t *testing.T) {
|
||||||
|
|
|
@ -241,6 +241,7 @@ func logPush(cfg *config.ConfYaml, status, token string, req *PushNotification,
|
||||||
Platform: req.Platform,
|
Platform: req.Platform,
|
||||||
Error: err,
|
Error: err,
|
||||||
HideToken: cfg.Log.HideToken,
|
HideToken: cfg.Log.HideToken,
|
||||||
|
HideMessage: cfg.Log.HideMessages,
|
||||||
Format: cfg.Log.Format,
|
Format: cfg.Log.Format,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue