mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Removed the legacy env var: LOGXI_FORMAT (#17822)
* Removed the legacy env var: LOGXI_FORMAT * Added changelog * Actually filled in the CL * Added the name of legacy env var
This commit is contained in:
3
changelog/17822.txt
Normal file
3
changelog/17822.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:change
|
||||||
|
logging: Removed legacy environment variable for log format ('LOGXI_FORMAT'), should use 'VAULT_LOG_FORMAT' instead
|
||||||
|
```
|
||||||
@@ -202,12 +202,10 @@ func (c *ServerCommand) Flags() *FlagSets {
|
|||||||
})
|
})
|
||||||
|
|
||||||
f.StringVar(&StringVar{
|
f.StringVar(&StringVar{
|
||||||
Name: "log-format",
|
Name: "log-format",
|
||||||
Target: &c.flagLogFormat,
|
Target: &c.flagLogFormat,
|
||||||
Default: notSetValue,
|
Default: notSetValue,
|
||||||
// EnvVar can't be just "VAULT_LOG_FORMAT", because more than one env var name is supported
|
EnvVar: "VAULT_LOG_FORMAT",
|
||||||
// for backwards compatibility reasons.
|
|
||||||
// See github.com/hashicorp/vault/sdk/helper/logging.ParseEnvLogFormat()
|
|
||||||
Completion: complete.PredictSet("standard", "json"),
|
Completion: complete.PredictSet("standard", "json"),
|
||||||
Usage: `Log format. Supported values are "standard" and "json".`,
|
Usage: `Log format. Supported values are "standard" and "json".`,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -60,16 +60,13 @@ func ParseLogFormat(format string) (LogFormat, error) {
|
|||||||
case "json":
|
case "json":
|
||||||
return JSONFormat, nil
|
return JSONFormat, nil
|
||||||
default:
|
default:
|
||||||
return UnspecifiedFormat, fmt.Errorf("Unknown log format: %s", format)
|
return UnspecifiedFormat, fmt.Errorf("unknown log format: %s", format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseEnvLogFormat parses the log format from an environment variable.
|
// ParseEnvLogFormat parses the log format from an environment variable.
|
||||||
func ParseEnvLogFormat() LogFormat {
|
func ParseEnvLogFormat() LogFormat {
|
||||||
logFormat := os.Getenv("VAULT_LOG_FORMAT")
|
logFormat := os.Getenv("VAULT_LOG_FORMAT")
|
||||||
if logFormat == "" {
|
|
||||||
logFormat = os.Getenv("LOGXI_FORMAT")
|
|
||||||
}
|
|
||||||
switch strings.ToLower(logFormat) {
|
switch strings.ToLower(logFormat) {
|
||||||
case "json", "vault_json", "vault-json", "vaultjson":
|
case "json", "vault_json", "vault-json", "vaultjson":
|
||||||
return JSONFormat
|
return JSONFormat
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func Test_ParseLogFormat(t *testing.T) {
|
|||||||
{format: "STANDARD", expected: StandardFormat, expectedErr: nil},
|
{format: "STANDARD", expected: StandardFormat, expectedErr: nil},
|
||||||
{format: "json", expected: JSONFormat, expectedErr: nil},
|
{format: "json", expected: JSONFormat, expectedErr: nil},
|
||||||
{format: " json ", expected: JSONFormat, expectedErr: nil},
|
{format: " json ", expected: JSONFormat, expectedErr: nil},
|
||||||
{format: "bogus", expected: UnspecifiedFormat, expectedErr: errors.New("Unknown log format: bogus")},
|
{format: "bogus", expected: UnspecifiedFormat, expectedErr: errors.New("unknown log format: bogus")},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -42,17 +42,6 @@ func Test_ParseEnv_VAULT_LOG_FORMAT(t *testing.T) {
|
|||||||
testParseEnvLogFormat(t, "VAULT_LOG_FORMAT")
|
testParseEnvLogFormat(t, "VAULT_LOG_FORMAT")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseEnv_LOGXI_FORMAT(t *testing.T) {
|
|
||||||
oldVLF := os.Getenv("VAULT_LOG_FORMAT")
|
|
||||||
defer os.Setenv("VAULT_LOG_FORMAT", oldVLF)
|
|
||||||
|
|
||||||
oldLogxi := os.Getenv("LOGXI_FORMAT")
|
|
||||||
defer os.Setenv("LOGXI_FORMAT", oldLogxi)
|
|
||||||
|
|
||||||
os.Setenv("VAULT_LOG_FORMAT", "")
|
|
||||||
testParseEnvLogFormat(t, "LOGXI_FORMAT")
|
|
||||||
}
|
|
||||||
|
|
||||||
func testParseEnvLogFormat(t *testing.T, name string) {
|
func testParseEnvLogFormat(t *testing.T, name string) {
|
||||||
env := []string{
|
env := []string{
|
||||||
"json", "vauLT_Json", "VAULT-JSON", "vaulTJSon",
|
"json", "vauLT_Json", "VAULT-JSON", "vaulTJSon",
|
||||||
|
|||||||
Reference in New Issue
Block a user