Removed unnecessary dependency from logutil package
util packages should have a few dependencies as possible, particularly from within the same repo, to prevent the application from creating import loops Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
bc63fa606e
commit
78892847ee
|
@ -276,7 +276,16 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password
|
|||
return err
|
||||
}
|
||||
|
||||
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
|
||||
logSettings := logutils.LogSettings{
|
||||
Enabled: conf.LogEnabled,
|
||||
MobileSystem: conf.LogMobileSystem,
|
||||
Level: conf.LogLevel,
|
||||
File: conf.LogFile,
|
||||
MaxSize: conf.LogMaxSize,
|
||||
MaxBackups: conf.LogMaxBackups,
|
||||
CompressRotated: conf.LogCompressRotated,
|
||||
}
|
||||
if err := logutils.OverrideRootLogWithConfig(logSettings, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -336,7 +345,17 @@ func (b *GethStatusBackend) startNodeWithAccount(acc multiaccounts.Account, pass
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
|
||||
|
||||
logSettings := logutils.LogSettings{
|
||||
Enabled: conf.LogEnabled,
|
||||
MobileSystem: conf.LogMobileSystem,
|
||||
Level: conf.LogLevel,
|
||||
File: conf.LogFile,
|
||||
MaxSize: conf.LogMaxSize,
|
||||
MaxBackups: conf.LogMaxBackups,
|
||||
CompressRotated: conf.LogCompressRotated,
|
||||
}
|
||||
if err := logutils.OverrideRootLogWithConfig(logSettings, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.account = &acc
|
||||
|
|
|
@ -262,8 +262,17 @@ func setupLogging(config *params.NodeConfig) {
|
|||
config.LogLevel = *logLevel
|
||||
}
|
||||
|
||||
logSettings := logutils.LogSettings{
|
||||
Enabled: config.LogEnabled,
|
||||
MobileSystem: config.LogMobileSystem,
|
||||
Level: config.LogLevel,
|
||||
File: config.LogFile,
|
||||
MaxSize: config.LogMaxSize,
|
||||
MaxBackups: config.LogMaxBackups,
|
||||
CompressRotated: config.LogCompressRotated,
|
||||
}
|
||||
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
|
||||
if err := logutils.OverrideRootLogWithConfig(config, colors); err != nil {
|
||||
if err := logutils.OverrideRootLogWithConfig(logSettings, colors); err != nil {
|
||||
stdlog.Fatalf("Error initializing logger: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,8 +255,17 @@ func setupLogging(config *params.NodeConfig) {
|
|||
config.LogLevel = *logLevel
|
||||
}
|
||||
|
||||
logSettings := logutils.LogSettings{
|
||||
Enabled: config.LogEnabled,
|
||||
MobileSystem: config.LogMobileSystem,
|
||||
Level: config.LogLevel,
|
||||
File: config.LogFile,
|
||||
MaxSize: config.LogMaxSize,
|
||||
MaxBackups: config.LogMaxBackups,
|
||||
CompressRotated: config.LogCompressRotated,
|
||||
}
|
||||
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
|
||||
if err := logutils.OverrideRootLogWithConfig(config, colors); err != nil {
|
||||
if err := logutils.OverrideRootLogWithConfig(logSettings, colors); err != nil {
|
||||
stdlog.Fatalf("Error initializing logger: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package logutils
|
||||
|
||||
import (
|
||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
|
|
@ -5,28 +5,36 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
|
||||
"github.com/status-im/status-go/params"
|
||||
)
|
||||
|
||||
type LogSettings struct {
|
||||
Enabled bool
|
||||
MobileSystem bool
|
||||
Level string
|
||||
File string
|
||||
MaxSize int
|
||||
MaxBackups int
|
||||
CompressRotated bool
|
||||
}
|
||||
|
||||
// OverrideWithStdLogger overwrites ethereum's root logger with a logger from golang std lib.
|
||||
func OverrideWithStdLogger(config *params.NodeConfig) error {
|
||||
return enableRootLog(config.LogLevel, NewStdHandler(log.LogfmtFormat()))
|
||||
func OverrideWithStdLogger(logLevel string) error {
|
||||
return enableRootLog(logLevel, NewStdHandler(log.LogfmtFormat()))
|
||||
}
|
||||
|
||||
// OverrideRootLogWithConfig derives all configuration from params.NodeConfig and configures logger using it.
|
||||
func OverrideRootLogWithConfig(config *params.NodeConfig, colors bool) error {
|
||||
if !config.LogEnabled {
|
||||
func OverrideRootLogWithConfig(settings LogSettings, colors bool) error {
|
||||
if !settings.Enabled {
|
||||
return nil
|
||||
}
|
||||
if config.LogMobileSystem {
|
||||
return OverrideWithStdLogger(config)
|
||||
if settings.MobileSystem {
|
||||
return OverrideWithStdLogger(settings.Level)
|
||||
}
|
||||
return OverrideRootLog(config.LogEnabled, config.LogLevel, FileOptions{
|
||||
Filename: config.LogFile,
|
||||
MaxSize: config.LogMaxSize,
|
||||
MaxBackups: config.LogMaxBackups,
|
||||
Compress: config.LogCompressRotated,
|
||||
return OverrideRootLog(settings.Enabled, settings.Level, FileOptions{
|
||||
Filename: settings.File,
|
||||
MaxSize: settings.MaxSize,
|
||||
MaxBackups: settings.MaxBackups,
|
||||
Compress: settings.CompressRotated,
|
||||
}, colors)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue