mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-09 03:21:19 +00:00
Config option for JSON output formatter (#2843)
* Introduce a structured logging option * rename StructuredLog to LogFormat * add changelog entry * move log_format under log_level
This commit is contained in:
parent
b646437ec7
commit
06225e332e
@ -26,6 +26,8 @@ program](https://hackerone.com/tendermint).
|
|||||||
|
|
||||||
|
|
||||||
### FEATURES:
|
### FEATURES:
|
||||||
|
- [log] new `log_format` config option, which can be set to 'plain' for colored
|
||||||
|
text or 'json' for JSON output
|
||||||
|
|
||||||
### IMPROVEMENTS:
|
### IMPROVEMENTS:
|
||||||
|
|
||||||
|
@ -54,6 +54,9 @@ var RootCmd = &cobra.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if config.LogFormat == cfg.LogFormatJSON {
|
||||||
|
logger = log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout))
|
||||||
|
}
|
||||||
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -14,6 +14,11 @@ const (
|
|||||||
FuzzModeDrop = iota
|
FuzzModeDrop = iota
|
||||||
// FuzzModeDelay is a mode in which we randomly sleep
|
// FuzzModeDelay is a mode in which we randomly sleep
|
||||||
FuzzModeDelay
|
FuzzModeDelay
|
||||||
|
|
||||||
|
// LogFormatPlain is a format for colored text
|
||||||
|
LogFormatPlain = "plain"
|
||||||
|
// LogFormatJSON is a format for json output
|
||||||
|
LogFormatJSON = "json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE: Most of the structs & relevant comments + the
|
// NOTE: Most of the structs & relevant comments + the
|
||||||
@ -94,6 +99,9 @@ func (cfg *Config) SetRoot(root string) *Config {
|
|||||||
// ValidateBasic performs basic validation (checking param bounds, etc.) and
|
// ValidateBasic performs basic validation (checking param bounds, etc.) and
|
||||||
// returns an error if any check fails.
|
// returns an error if any check fails.
|
||||||
func (cfg *Config) ValidateBasic() error {
|
func (cfg *Config) ValidateBasic() error {
|
||||||
|
if err := cfg.BaseConfig.ValidateBasic(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := cfg.RPC.ValidateBasic(); err != nil {
|
if err := cfg.RPC.ValidateBasic(); err != nil {
|
||||||
return errors.Wrap(err, "Error in [rpc] section")
|
return errors.Wrap(err, "Error in [rpc] section")
|
||||||
}
|
}
|
||||||
@ -145,6 +153,9 @@ type BaseConfig struct {
|
|||||||
// Output level for logging
|
// Output level for logging
|
||||||
LogLevel string `mapstructure:"log_level"`
|
LogLevel string `mapstructure:"log_level"`
|
||||||
|
|
||||||
|
// Output format: 'plain' (colored text) or 'json'
|
||||||
|
LogFormat string `mapstructure:"log_format"`
|
||||||
|
|
||||||
// Path to the JSON file containing the initial validator set and other meta data
|
// Path to the JSON file containing the initial validator set and other meta data
|
||||||
Genesis string `mapstructure:"genesis_file"`
|
Genesis string `mapstructure:"genesis_file"`
|
||||||
|
|
||||||
@ -179,6 +190,7 @@ func DefaultBaseConfig() BaseConfig {
|
|||||||
ProxyApp: "tcp://127.0.0.1:26658",
|
ProxyApp: "tcp://127.0.0.1:26658",
|
||||||
ABCI: "socket",
|
ABCI: "socket",
|
||||||
LogLevel: DefaultPackageLogLevels(),
|
LogLevel: DefaultPackageLogLevels(),
|
||||||
|
LogFormat: LogFormatPlain,
|
||||||
ProfListenAddress: "",
|
ProfListenAddress: "",
|
||||||
FastSync: true,
|
FastSync: true,
|
||||||
FilterPeers: false,
|
FilterPeers: false,
|
||||||
@ -221,6 +233,17 @@ func (cfg BaseConfig) DBDir() string {
|
|||||||
return rootify(cfg.DBPath, cfg.RootDir)
|
return rootify(cfg.DBPath, cfg.RootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateBasic performs basic validation (checking param bounds, etc.) and
|
||||||
|
// returns an error if any check fails.
|
||||||
|
func (cfg BaseConfig) ValidateBasic() error {
|
||||||
|
switch cfg.LogFormat {
|
||||||
|
case LogFormatPlain, LogFormatJSON:
|
||||||
|
default:
|
||||||
|
return errors.New("unknown log_format (must be 'plain' or 'json')")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultLogLevel returns a default log level of "error"
|
// DefaultLogLevel returns a default log level of "error"
|
||||||
func DefaultLogLevel() string {
|
func DefaultLogLevel() string {
|
||||||
return "error"
|
return "error"
|
||||||
|
@ -86,6 +86,9 @@ db_dir = "{{ js .BaseConfig.DBPath }}"
|
|||||||
# Output level for logging, including package level options
|
# Output level for logging, including package level options
|
||||||
log_level = "{{ .BaseConfig.LogLevel }}"
|
log_level = "{{ .BaseConfig.LogLevel }}"
|
||||||
|
|
||||||
|
# Output format: 'plain' (colored text) or 'json'
|
||||||
|
log_format = "{{ .BaseConfig.LogFormat }}"
|
||||||
|
|
||||||
##### additional base config options #####
|
##### additional base config options #####
|
||||||
|
|
||||||
# Path to the JSON file containing the initial validator set and other meta data
|
# Path to the JSON file containing the initial validator set and other meta data
|
||||||
|
@ -39,6 +39,9 @@ db_dir = "data"
|
|||||||
# Output level for logging
|
# Output level for logging
|
||||||
log_level = "state:info,*:error"
|
log_level = "state:info,*:error"
|
||||||
|
|
||||||
|
# Output format: 'plain' (colored text) or 'json'
|
||||||
|
log_format = "plain"
|
||||||
|
|
||||||
##### additional base config options #####
|
##### additional base config options #####
|
||||||
|
|
||||||
# The ID of the chain to join (should be signed with every transaction and vote)
|
# The ID of the chain to join (should be signed with every transaction and vote)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user