Chore: Make logger mutable for regression test (#49146)

* Log: make logger mutable

* remove flag from public configuration
This commit is contained in:
ying-jeanne 2022-05-18 17:04:52 +02:00 committed by GitHub
parent 71e1305364
commit 4e3f53f106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -378,6 +378,11 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) error {
return err
}
logEnabled := cfg.Section("log").Key("enabled").MustBool(true)
if !logEnabled {
return nil
}
defaultLevelName, _ := getLogLevelFromConfig("log", "info", cfg)
defaultFilters := getFilters(util.SplitString(cfg.Section("log").Key("filters").String()))

View File

@ -93,6 +93,7 @@ func SetUpDatabase(t *testing.T, grafDir string) *sqlstore.SQLStore {
}
// CreateGrafDir creates the Grafana directory.
// The log by default is muted in the regression test, to activate it, pass option EnableLog = true
func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
t.Helper()
@ -178,6 +179,7 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
logSect, err := cfg.NewSection("log")
require.NoError(t, err)
_, err = logSect.NewKey("level", "debug")
require.NoError(t, err)
@ -288,6 +290,12 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
_, err = unifiedAlertingSection.NewKey("disabled_orgs", disableOrgStr)
require.NoError(t, err)
}
if !o.EnableLog {
logSection, err := getOrCreateSection("log")
require.NoError(t, err)
_, err = logSection.NewKey("enabled", "false")
require.NoError(t, err)
}
}
cfgPath := filepath.Join(cfgDir, "test.ini")
@ -316,4 +324,5 @@ type GrafanaOpts struct {
DisableLegacyAlerting bool
EnableUnifiedAlerting bool
UnifiedAlertingDisabledOrgs []int64
EnableLog bool
}