common logger
What does this MR do?
Adds a common logger format for our analyzers to use with logrus. Sample usage:
import (
"gitlab.com/gitlab-org/security-products/analyzers/common/v2/logutil"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&logutil.Formatter{})
log.Info("foo")
log.SetFormatter(&logutil.Formatter{Project:"secrets"})
log.Info("bar")
log.SetFormatter(&logutil.Formatter{Project:"secrets", TimestampFormat:time.RFC3339Nano})
log.Info("baz")
// resetting to default
log.SetFormatter(&logutil.Formatter{})
log.Debug("foo")
log.Info("foo")
log.Warn("bar")
log.Error("baz")
log.Fatalf("goodbye %s", "world")
}
/*
example output:
[INFO] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ foo
[INFO] [secrets] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ bar
[INFO] [secrets] [2020-03-15T10:18:08.305231-04:00] ▶ baz
[INFO] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ foo
[WARN] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ bar
[ERRO] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ baz
[FATA] [Sun, 15 Mar 2020 10:18:08 EDT] ▶ goodbye world
*/
What are the relevant issue numbers?
Does this MR meet the acceptance criteria?
-
Changelog entry added -
Documentation created/updated for GitLab EE, if necessary -
Documentation created/updated for this project, if necessary -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Job definition updated, if necessary -
Conforms to the code review guidelines -
Conforms to the Go guidelines -
Security reports checked/validated by reviewer
Edited by 🤖 GitLab Bot 🤖