Add log redacting, controlled by the new EnableLogRedacting config option (default true)
Imported redacting code from https://github.com/whuang8/redactrus (thanks William Huang) Didn't use it as a dependency as it was too small and we want to keep dependencies at a minimum
This commit is contained in:
+22
@@ -16,6 +16,22 @@ type Level uint8
|
||||
|
||||
type LevelFunc = func(ctx interface{}, msg interface{}, keyValuePairs ...interface{})
|
||||
|
||||
var redacted = &Hook{
|
||||
AcceptedLevels: logrus.AllLevels,
|
||||
RedactionList: []string{
|
||||
// Keys from the config
|
||||
"(ApiKey:\")[\\w]*",
|
||||
"(Secret:\")[\\w]*",
|
||||
"(Spotify.*ID:\")[\\w]*",
|
||||
|
||||
// Subsonic query params
|
||||
"([^\\w]t=)[\\w]+",
|
||||
"([^\\w]s=)[\\w]+",
|
||||
"([^\\w]p=)[\\w]+",
|
||||
"([^\\w]jwt=)[\\w]+",
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
LevelCritical = Level(logrus.FatalLevel)
|
||||
LevelError = Level(logrus.ErrorLevel)
|
||||
@@ -65,6 +81,12 @@ func SetLogSourceLine(enabled bool) {
|
||||
logSourceLine = enabled
|
||||
}
|
||||
|
||||
func SetRedacting(enabled bool) {
|
||||
if enabled {
|
||||
defaultLogger.AddHook(redacted)
|
||||
}
|
||||
}
|
||||
|
||||
func NewContext(ctx context.Context, keyValuePairs ...interface{}) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
|
||||
Reference in New Issue
Block a user