[#224] Refactor logger tag configuration
Some checks failed
/ DCO (pull_request) Successful in 32s
/ Vulncheck (pull_request) Successful in 52s
/ Builds (pull_request) Successful in 59s
/ OCI image (pull_request) Successful in 1m19s
/ Lint (pull_request) Failing after 1m7s
/ Tests (pull_request) Successful in 1m2s
/ Integration tests (pull_request) Successful in 5m29s

Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
Pavel Pogodaev 2025-03-21 13:38:43 +03:00
parent 0f73da258b
commit 178cb19ea4
3 changed files with 17 additions and 14 deletions

View file

@ -113,7 +113,7 @@ const (
cfgLoggerTags = "logger.tags" cfgLoggerTags = "logger.tags"
cfgLoggerTagsPrefixTmpl = cfgLoggerTags + ".%d." cfgLoggerTagsPrefixTmpl = cfgLoggerTags + ".%d."
cfgLoggerTagsNameTmpl = cfgLoggerTagsPrefixTmpl + "name" cfgLoggerTagsNameTmpl = cfgLoggerTagsPrefixTmpl + "names"
cfgLoggerTagsLevelTmpl = cfgLoggerTagsPrefixTmpl + "level" cfgLoggerTagsLevelTmpl = cfgLoggerTagsPrefixTmpl + "level"
// Wallet. // Wallet.
@ -516,8 +516,8 @@ func fetchLogTagsConfig(v *viper.Viper, defaultLvl zapcore.Level) (map[string]za
res := make(map[string]zapcore.Level) res := make(map[string]zapcore.Level)
for i := 0; ; i++ { for i := 0; ; i++ {
name := v.GetString(fmt.Sprintf(cfgLoggerTagsNameTmpl, i)) tagNames := v.GetString(fmt.Sprintf(cfgLoggerTagsNameTmpl, i))
if name == "" { if tagNames == "" {
break break
} }
@ -529,7 +529,12 @@ func fetchLogTagsConfig(v *viper.Viper, defaultLvl zapcore.Level) (map[string]za
} }
} }
res[name] = lvl for _, tagName := range strings.Split(tagNames, ",") {
tagName = strings.TrimSpace(tagNames)
if len(tagName) != 0 {
res[tagName] = lvl
}
}
} }
if len(res) == 0 && !v.IsSet(cfgLoggerTags) { if len(res) == 0 && !v.IsSet(cfgLoggerTags) {

View file

@ -30,8 +30,7 @@ logger:
thereafter: 100 thereafter: 100
interval: 1s interval: 1s
tags: tags:
- name: app - names: app,datapath
- name: datapath
level: debug level: debug
server: server:

View file

@ -176,10 +176,9 @@ logger:
thereafter: 100 thereafter: 100
interval: 1s interval: 1s
tags: tags:
- name: "app" - names: "app,datapath"
level: info level: info
- name: "datapath" - names: "external_storage_tree"
- name: "external_storage_tree"
``` ```
| Parameter | Type | SIGHUP reload | Default value | Description | | Parameter | Type | SIGHUP reload | Default value | Description |
@ -199,14 +198,14 @@ parameter. Available tags:
```yaml ```yaml
tags: tags:
- name: "app" - names: "app,datapath"
level: info level: info
``` ```
| Parameter | Type | SIGHUP reload | Default value | Description | | Parameter | Type | SIGHUP reload | Default value | Description |
|-----------------------|------------|---------------|---------------------------|-------------------------------------------------------------------------------------------------------| |-----------|------------|---------------|---------------------------|-------------------------------------------------------------------------------------------------------|
| `name` | `string` | yes | | Tag name. Possible values see below in `Tag values` section. | | `names` | `[]string` | yes | | Tag names separated by `,`. Possible values see below in `Tag values` section. |
| `level` | `string` | yes | Value from `logger.level` | Logging level for specific tag. Possible values: `debug`, `info`, `warn`, `dpanic`, `panic`, `fatal`. | | `level` | `string` | yes | Value from `logger.level` | Logging level for specific tag. Possible values: `debug`, `info`, `warn`, `dpanic`, `panic`, `fatal`. |
### Tag values ### Tag values