remove the global log error/warn etc functions (#41404)

* remove the global log error/warn etc functions and use request context logger whenever possible
This commit is contained in:
ying-jeanne
2021-11-08 17:56:56 +01:00
committed by GitHub
parent bda60f3458
commit 54de1078c8
28 changed files with 88 additions and 93 deletions

View File

@@ -11,6 +11,8 @@ import (
api "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
)
var cfglogger = log.New("notifier.config")
func PersistTemplates(cfg *api.PostableUserConfig, path string) ([]string, bool, error) {
if len(cfg.TemplateFiles) < 1 {
return nil, false, nil
@@ -52,7 +54,7 @@ func PersistTemplates(cfg *api.PostableUserConfig, path string) ([]string, bool,
// Now that we have the list of _actual_ templates, let's remove the ones that we don't need.
existingFiles, err := ioutil.ReadDir(path)
if err != nil {
log.Error("unable to read directory for deleting Alertmanager templates", "err", err, "path", path)
cfglogger.Error("unable to read directory for deleting Alertmanager templates", "err", err, "path", path)
}
for _, existingFile := range existingFiles {
p := filepath.Join(path, existingFile.Name())
@@ -61,7 +63,7 @@ func PersistTemplates(cfg *api.PostableUserConfig, path string) ([]string, bool,
templatesChanged = true
err := os.Remove(p)
if err != nil {
log.Error("unable to delete template", "err", err, "file", p)
cfglogger.Error("unable to delete template", "err", err, "file", p)
}
}
}

View File

@@ -543,7 +543,7 @@ func (sch *schedule) ruleRoutine(grafanaCtx context.Context, key models.AlertRul
return evaluate(currentRule, attempt, ctx)
})
if err != nil {
log.Error("evaluation failed after all retries", "err", err)
logger.Error("evaluation failed after all retries", "err", err)
}
}()
case <-stopCh: