Skip to content

Commit

Permalink
Fixes intelsdi-x#1438, set log level for logs from grpc to user defined
Browse files Browse the repository at this point in the history
set Out and Formatter for grpc logs
  • Loading branch information
katarzyna-z committed Mar 6, 2017
1 parent 96d9c6a commit f866c02
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions snapteld.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/intelsdi-x/snap/mgmt/tribe/agreement"
"github.com/intelsdi-x/snap/pkg/cfgfile"
"github.com/intelsdi-x/snap/scheduler"
"google.golang.org/grpc/grpclog"
)

var (
Expand Down Expand Up @@ -246,6 +247,9 @@ func action(ctx *cli.Context) error {
log.Fatal("Errors found after applying command-line flags")
}

//create a new logger to prepare configuration for grpc logger
grpcLogger := log.New()

// If logPath is set, we verify the logPath and set it so that all logging
// goes to the log file instead of stdout.
logPath := cfg.LogPath
Expand All @@ -267,6 +271,7 @@ func action(ctx *cli.Context) error {
}
defer file.Close()
log.SetOutput(file)
grpcLogger.Out = file
}
// Because even though github.com/Sirupsen/logrus states that
// 'Logs the event in colors if stdout is a tty, otherwise without colors'
Expand All @@ -278,15 +283,24 @@ func action(ctx *cli.Context) error {
// redirect mechanisms like # snapteld -t 0 -l 1 2>&1 | tee my.log
if !cfg.LogColors {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableColors: true})
grpcLogger.Formatter = &log.TextFormatter{FullTimestamp: true, DisableColors: true}
} else {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
grpcLogger.Formatter = &log.TextFormatter{FullTimestamp: true}
}

// Validate log level and trust level settings for snapteld
validateLevelSettings(cfg.LogLevel, cfg.Control.PluginTrust)

// Switch log level to user defined
log.SetLevel(getLevel(cfg.LogLevel))

// Set log level for logs from grpc to user defined
grpcLogger.Level = getLevel(cfg.LogLevel)

//Set configuration for grpc logger
grpclog.SetLogger(grpcLogger)

log.Info("setting log level to: ", l[cfg.LogLevel])

log.Info("Starting snapteld (version: ", gitversion, ")")
Expand Down

0 comments on commit f866c02

Please sign in to comment.