Skip to content

Commit

Permalink
fix: init-network with config.toml without setting TimeFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC committed Apr 3, 2023
1 parent bd76c25 commit d690074
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
12 changes: 6 additions & 6 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 10 additions & 14 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d690074

Please sign in to comment.