From d6900748b2a2e6b56f7e01c4f38f9d240c9c4c5b Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Mon, 3 Apr 2023 20:30:19 +0800 Subject: [PATCH] fix: init-network with config.toml without setting TimeFormat --- node/config.go | 12 ++++++------ node/node.go | 24 ++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/node/config.go b/node/config.go index baa7a8f50d..a9fb55335e 100644 --- a/node/config.go +++ b/node/config.go @@ -502,13 +502,13 @@ func (c *Config) warnOnce(w *bool, format string, args ...interface{}) { } type LogConfig struct { - FileRoot *string - FilePath *string - MaxBytesSize *uint - Level *string + FileRoot string + FilePath string + MaxBytesSize uint + Level string // TermTimeFormat is the time format used for console logging. - TermTimeFormat *string + TermTimeFormat string // TimeFormat is the time format used for file logging. - TimeFormat *string + TimeFormat string } diff --git a/node/node.go b/node/node.go index ef256f77e7..caaac232a8 100644 --- a/node/node.go +++ b/node/node.go @@ -86,25 +86,21 @@ func New(conf *Config) (*Node, error) { conf.DataDir = absdatadir } if conf.LogConfig != nil { - if conf.LogConfig.TermTimeFormat != nil && *conf.LogConfig.TermTimeFormat != "" { - log.SetTermTimeFormat(*conf.LogConfig.TermTimeFormat) + if conf.LogConfig.TermTimeFormat != "" { + log.SetTermTimeFormat(conf.LogConfig.TermTimeFormat) } - if conf.LogConfig.TimeFormat != nil && *conf.LogConfig.TimeFormat != "" { - log.SetTimeFormat(*conf.LogConfig.TimeFormat) + if conf.LogConfig.TimeFormat != "" { + log.SetTimeFormat(conf.LogConfig.TimeFormat) } - if conf.LogConfig.FileRoot != nil && conf.LogConfig.FilePath != nil && - conf.LogConfig.MaxBytesSize != nil && conf.LogConfig.Level != nil { - // log to file - logFilePath := "" - if *conf.LogConfig.FileRoot == "" { - logFilePath = path.Join(conf.DataDir, *conf.LogConfig.FilePath) - } else { - logFilePath = path.Join(*conf.LogConfig.FileRoot, *conf.LogConfig.FilePath) - } - log.Root().SetHandler(log.NewFileLvlHandler(logFilePath, *conf.LogConfig.MaxBytesSize, *conf.LogConfig.Level)) + logFilePath := "" + if conf.LogConfig.FileRoot == "" { + logFilePath = path.Join(conf.DataDir, conf.LogConfig.FilePath) + } else { + logFilePath = path.Join(conf.LogConfig.FileRoot, conf.LogConfig.FilePath) } + log.Root().SetHandler(log.NewFileLvlHandler(logFilePath, conf.LogConfig.MaxBytesSize, conf.LogConfig.Level)) } if conf.Logger == nil { conf.Logger = log.New()