Skip to content

common logger

Zach Rice requested to merge log-pkg into master

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?

Edited by 🤖 GitLab Bot 🤖

Merge request reports