🚚 Rename stdout.config.formatter to format
This commit is contained in:
parent
d6482952a4
commit
8086029b03
6 changed files with 8 additions and 9 deletions
|
|
@ -123,7 +123,7 @@ Each separate output has its own set of configuration. So, replace `which-one` w
|
||||||
|
|
||||||
*This section may change in the near future. We're considering supporting multiple formats.*
|
*This section may change in the near future. We're considering supporting multiple formats.*
|
||||||
|
|
||||||
- `formatter`: Which formatter to use when outputting data. This value is used by `my-log drop` to output the new entry.
|
- `format`: Which formatter to use when outputting data. This value is also used by `my-log drop` to output the new entry.
|
||||||
|
|
||||||
### `[formatters]`
|
### `[formatters]`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func init() {
|
||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&config.ConfigPath, "config", "c", config.ConfigPath, "config file")
|
rootCmd.PersistentFlags().StringVarP(&config.ConfigPath, "config", "c", config.ConfigPath, "config file")
|
||||||
rootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.formatter=json")
|
rootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.format=json")
|
||||||
|
|
||||||
// Cobra also supports local flags, which will only run
|
// Cobra also supports local flags, which will only run
|
||||||
// when this action is called directly.
|
// when this action is called directly.
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ dotFolder = true
|
||||||
enabled = true
|
enabled = true
|
||||||
[output.stdout.config]
|
[output.stdout.config]
|
||||||
# Formatter to use when outputting to stdout
|
# Formatter to use when outputting to stdout
|
||||||
formatter = "plain"
|
format = "plain"
|
||||||
|
|
||||||
[formatters]
|
[formatters]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,14 @@ func TestStdoutMissing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStdoutLoad(t *testing.T) {
|
func TestStdoutLoad(t *testing.T) {
|
||||||
os.Setenv("LOG_STDOUT_FORMATTER", "json")
|
os.Setenv("LOG_STDOUT_FORMAT", "json")
|
||||||
defer os.Unsetenv("LOG_STDOUT_FORMATTER")
|
defer os.Unsetenv("LOG_STDOUT_FORMAT")
|
||||||
os.Setenv("LOG_STDOUT_ENABLED", "true")
|
os.Setenv("LOG_STDOUT_ENABLED", "true")
|
||||||
defer os.Unsetenv("LOG_STDOUT_ENABLED")
|
defer os.Unsetenv("LOG_STDOUT_ENABLED")
|
||||||
c, _ := Load()
|
c, _ := Load()
|
||||||
std, en := c.Outputs.Stdout()
|
std, en := c.Outputs.Stdout()
|
||||||
assert.True(t, en)
|
assert.True(t, en)
|
||||||
assert.Equal(t, "json", std.Formatter)
|
assert.Equal(t, "json", std.Format)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatJson(t *testing.T) {
|
func TestFormatJson(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type Output struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stdout struct {
|
type Stdout struct {
|
||||||
Formatter string `env:"LOG_STDOUT_FORMATTER" mapstructure:"formatter"`
|
Format string `env:"LOG_STDOUT_FORMAT" mapstructure:"format"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type stdoutEnabled struct {
|
type stdoutEnabled struct {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ func Preferred() (f Formatter, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
std, _ := conf.Outputs.Stdout()
|
std, _ := conf.Outputs.Stdout()
|
||||||
kind := std.Formatter
|
return New(std.Format)
|
||||||
return New(kind)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(kind string) (f Formatter, err error) {
|
func New(kind string) (f Formatter, err error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue