Skip to content

Commit

Permalink
cmdutil: Add env opt to report logrus caller
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Xie committed Dec 25, 2019
1 parent d59dd2c commit c551678
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmdutil/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmdutil
import (
"io"
"os"
"strings"

"github.com/dmksnnk/sentryhook"
raven "github.com/getsentry/raven-go"
Expand All @@ -15,6 +16,7 @@ import (
const (
EnvLogrusLevel = "LOGRUS_LEVEL"
EnvLogrusFormat = "LOGRUS_FORMAT"
EnvLogrusCaller = "LOGRUS_CALLER"
)

// Valid environment values for the key EnvLogrusFormat.
Expand All @@ -40,6 +42,15 @@ func NewLogger(opts ...LogrusOption) *logrus.Entry {
log := logrus.New()
log.SetOutput(cfg.Output)

// Set 'report caller' option.
{
report := os.Getenv(EnvLogrusCaller)
switch strings.ToLower(report) {
case "true", "1":
log.SetReportCaller(true)
}
}

// Set level.
if l, ok := os.LookupEnv(EnvLogrusLevel); ok {
level, err := logrus.ParseLevel(l)
Expand Down Expand Up @@ -92,7 +103,7 @@ func WithSentryHook(rc *raven.Client) LogrusOption {
type (
// A LogrusConfig configures a logrus.Logger.
LogrusConfig struct {
// Logging-related options.
// Output-related options.
Output io.Writer
TextFormatter logrus.TextFormatter
JSONFormatter logrus.JSONFormatter
Expand Down

0 comments on commit c551678

Please sign in to comment.