Add LogEnabled attribute to NodeConfig to, used in the call from status-react (#866)

* add LogEnabled attribute to NodeConfig, used in the call from status-react

* fix use of OverrideRootLogin in tests

* enable logger in tests based on LogLevel

* move LogEnabled before LogFile
This commit is contained in:
Andrea Franz 2018-04-26 18:28:42 +02:00 committed by GitHub
parent a23b607597
commit 5f45f6498d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 4 deletions

View File

@ -102,7 +102,7 @@ func main() {
return return
} }
if err := logutils.OverrideRootLog(config.LogLevel, config.LogFile, true); err != nil { if err := logutils.OverrideRootLog(config.LogEnabled, config.LogLevel, config.LogFile, true); err != nil {
stdlog.Fatalf("Error initializing logger: %s", err) stdlog.Fatalf("Error initializing logger: %s", err)
} }
@ -230,10 +230,15 @@ func makeNodeConfig() (*params.NodeConfig, error) {
if *logLevel != "" { if *logLevel != "" {
nodeConfig.LogLevel = *logLevel nodeConfig.LogLevel = *logLevel
} }
if *logFile != "" { if *logFile != "" {
nodeConfig.LogFile = *logFile nodeConfig.LogFile = *logFile
} }
if *logLevel != "" || *logFile != "" {
nodeConfig.LogEnabled = true
}
nodeConfig.RPCEnabled = *httpEnabled nodeConfig.RPCEnabled = *httpEnabled
nodeConfig.WhisperConfig.Enabled = *whisperEnabled nodeConfig.WhisperConfig.Enabled = *whisperEnabled
nodeConfig.MaxPeers = *maxPeers nodeConfig.MaxPeers = *maxPeers

View File

@ -279,6 +279,9 @@ type NodeConfig struct {
log log.Logger log log.Logger
// LogEnabled enables the logger
LogEnabled bool `json:"LogEnabled"`
// LogFile is filename where exposed logs get written to // LogFile is filename where exposed logs get written to
LogFile string LogFile string

View File

@ -41,7 +41,7 @@ func StartNode(configJSON *C.char) *C.char {
return makeJSONResponse(err) return makeJSONResponse(err)
} }
if err := logutils.OverrideRootLog(config.LogLevel, config.LogFile, false); err != nil { if err := logutils.OverrideRootLog(config.LogEnabled, config.LogLevel, config.LogFile, false); err != nil {
return makeJSONResponse(err) return makeJSONResponse(err)
} }

View File

@ -9,7 +9,20 @@ import (
// OverrideRootLog overrides root logger with file handler, if defined, // OverrideRootLog overrides root logger with file handler, if defined,
// and log level (defaults to INFO). // and log level (defaults to INFO).
func OverrideRootLog(levelStr, logFile string, terminal bool) error { func OverrideRootLog(enabled bool, levelStr string, logFile string, terminal bool) error {
if !enabled {
disableRootLog()
return nil
}
return enableRootLog(levelStr, logFile, terminal)
}
func disableRootLog() {
log.Root().SetHandler(log.DiscardHandler())
}
func enableRootLog(levelStr string, logFile string, terminal bool) error {
var ( var (
handler log.Handler handler log.Handler
err error err error

View File

@ -70,7 +70,8 @@ func init() {
flag.Parse() flag.Parse()
// set up logger // set up logger
if err := logutils.OverrideRootLog(*logLevel, "", true); err != nil { loggerEnabled := *logLevel != ""
if err := logutils.OverrideRootLog(loggerEnabled, *logLevel, "", true); err != nil {
panic(err) panic(err)
} }