Skip to content

Commit

Permalink
Add logs destination to config #133
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Nov 15, 2018
1 parent dfd4653 commit f3d07b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ type BaseConfig struct {
APIPerIPLimit int `mapstructure:"api_per_ip_limit"`

APIPerIPLimitWindow time.Duration `mapstructure:"api_per_ip_limit_window"`

LogPath string `mapstructure:"log_path"`
}

// DefaultBaseConfig returns a default base configuration for a Tendermint node
Expand All @@ -261,6 +263,7 @@ func DefaultBaseConfig() BaseConfig {
APISimultaneousRequests: 100,
APIPerIPLimit: 1000,
APIPerIPLimitWindow: 60 * time.Second,
LogPath: "stdout",
}
}

Expand Down
3 changes: 3 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ db_path = "{{ js .BaseConfig.DBPath }}"
# Output level for logging, including package level options
log_level = "{{ .BaseConfig.LogLevel }}"
# Path to file for logs, "stdout" by default
log_path = "{{ .BaseConfig.LogPath }}"
##### additional base config options #####
# Path to the JSON file containing the private key to use as a validator in the consensus protocol
Expand Down
23 changes: 21 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ var (
)

func init() {
logger, _ := flags.ParseLogLevel(cfg.LogLevel, log.NewTMLogger(os.Stdout), "info")
SetLogger(logger)
var l log.Logger

if cfg.LogPath != "stdout" {
file, err := os.OpenFile(cfg.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)

if err != nil {
panic(err)
}

l = log.NewTMLogger(file)
} else {
l = log.NewTMLogger(os.Stdout)
}

l, err := flags.ParseLogLevel(cfg.LogLevel, l, "info")

if err != nil {
panic(err)
}

SetLogger(l)
}

func SetLogger(l log.Logger) {
Expand Down

0 comments on commit f3d07b4

Please sign in to comment.