[MM-54319] Add AdvancedLoggingJSON setting to system console (#24733)
* Add AdvancedLoggingJSON setting to system console * Apply suggestions from code review Co-authored-by: Doug Lauder <wiggin77@warpmail.net> * Add validation for AdvancedLoggingJSON --------- Co-authored-by: Doug Lauder <wiggin77@warpmail.net> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0844968d81
Коммит
671cf6cc3d
@@ -1208,6 +1208,109 @@ func TestLdapSettingsIsValid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogSettingsIsValid(t *testing.T) {
|
||||
for name, test := range map[string]struct {
|
||||
LogSettings LogSettings
|
||||
ExpectError bool
|
||||
}{
|
||||
"empty": {
|
||||
LogSettings: LogSettings{},
|
||||
ExpectError: false,
|
||||
},
|
||||
"AdvancedLoggingJSON contains empty string": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(``),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
"AdvancedLoggingJSON contains empty JSON": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`{}`),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
"AdvancedLoggingJSON has JSON error ": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`
|
||||
{
|
||||
"foo": "bar",
|
||||
`),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"AdvancedLoggingJSON has missing target": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`
|
||||
{
|
||||
"foo": "bar",
|
||||
}
|
||||
`),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"AdvancedLoggingJSON has an unknown Type": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`
|
||||
{
|
||||
"console-log": {
|
||||
"Type": "XYZ",
|
||||
"Format": "json",
|
||||
"Levels": [
|
||||
{"ID": 10, "Name": "stdlog", "Stacktrace": false},
|
||||
{"ID": 5, "Name": "debug", "Stacktrace": false},
|
||||
{"ID": 4, "Name": "info", "Stacktrace": false, "color": 36},
|
||||
{"ID": 3, "Name": "warn", "Stacktrace": false, "color": 33},
|
||||
{"ID": 2, "Name": "error", "Stacktrace": true, "color": 31},
|
||||
{"ID": 1, "Name": "fatal", "Stacktrace": true},
|
||||
{"ID": 0, "Name": "panic", "Stacktrace": true}
|
||||
],
|
||||
"Options": {
|
||||
"Out": "stdout"
|
||||
},
|
||||
"MaxQueueSize": 1000
|
||||
}
|
||||
}
|
||||
`),
|
||||
},
|
||||
ExpectError: true,
|
||||
},
|
||||
"AdvancedLoggingJSON is valid": {
|
||||
LogSettings: LogSettings{
|
||||
AdvancedLoggingJSON: json.RawMessage(`
|
||||
{
|
||||
"console-log": {
|
||||
"Type": "console",
|
||||
"Format": "json",
|
||||
"Levels": [
|
||||
{"ID": 5, "Name": "debug", "Stacktrace": false},
|
||||
{"ID": 4, "Name": "info", "Stacktrace": false, "color": 36},
|
||||
{"ID": 3, "Name": "warn", "Stacktrace": false, "color": 33},
|
||||
{"ID": 2, "Name": "error", "Stacktrace": true, "color": 31}
|
||||
],
|
||||
"Options": {
|
||||
"Out": "stdout"
|
||||
},
|
||||
"MaxQueueSize": 1000
|
||||
}
|
||||
}
|
||||
`),
|
||||
},
|
||||
ExpectError: false,
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
test.LogSettings.SetDefaults()
|
||||
|
||||
appErr := test.LogSettings.isValid()
|
||||
if test.ExpectError {
|
||||
assert.NotNil(t, appErr)
|
||||
} else {
|
||||
assert.Nil(t, appErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanitize(t *testing.T) {
|
||||
c := Config{}
|
||||
c.SetDefaults()
|
||||
|
||||
Ссылка в новой задаче
Block a user