diff --git a/pkg/infra/log/log.go b/pkg/infra/log/log.go index efe85bbf84e..e3f89f3c146 100644 --- a/pkg/infra/log/log.go +++ b/pkg/infra/log/log.go @@ -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())) diff --git a/pkg/tests/testinfra/testinfra.go b/pkg/tests/testinfra/testinfra.go index 251a62ca3d5..5ebd80e79ba 100644 --- a/pkg/tests/testinfra/testinfra.go +++ b/pkg/tests/testinfra/testinfra.go @@ -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 }