[#224] Refactor logger tag configuration
All checks were successful
/ DCO (pull_request) Successful in 27s
/ Vulncheck (pull_request) Successful in 57s
/ Builds (pull_request) Successful in 59s
/ OCI image (pull_request) Successful in 1m20s
/ Lint (pull_request) Successful in 2m8s
/ Tests (pull_request) Successful in 1m30s
/ Integration tests (pull_request) Successful in 5m30s
All checks were successful
/ DCO (pull_request) Successful in 27s
/ Vulncheck (pull_request) Successful in 57s
/ Builds (pull_request) Successful in 59s
/ OCI image (pull_request) Successful in 1m20s
/ Lint (pull_request) Successful in 2m8s
/ Tests (pull_request) Successful in 1m30s
/ Integration tests (pull_request) Successful in 5m30s
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
0f73da258b
commit
8583dffb7c
5 changed files with 23 additions and 22 deletions
|
@ -73,14 +73,10 @@ func (c *zapCoreTagFilterWrapper) Write(entry zapcore.Entry, fields []zapcore.Fi
|
|||
func (c *zapCoreTagFilterWrapper) shouldSkip(entry zapcore.Entry, fields []zap.Field) bool {
|
||||
for _, field := range fields {
|
||||
if field.Key == logs.TagFieldName && field.Type == zapcore.StringType {
|
||||
if !c.settings.LevelEnabled(field.String, entry.Level) {
|
||||
return true
|
||||
}
|
||||
break
|
||||
return !c.settings.LevelEnabled(field.String, entry.Level)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return !c.Enabled(entry.Level)
|
||||
}
|
||||
|
||||
func (c *zapCoreTagFilterWrapper) Sync() error {
|
||||
|
|
|
@ -113,7 +113,7 @@ const (
|
|||
|
||||
cfgLoggerTags = "logger.tags"
|
||||
cfgLoggerTagsPrefixTmpl = cfgLoggerTags + ".%d."
|
||||
cfgLoggerTagsNameTmpl = cfgLoggerTagsPrefixTmpl + "name"
|
||||
cfgLoggerTagsNameTmpl = cfgLoggerTagsPrefixTmpl + "names"
|
||||
cfgLoggerTagsLevelTmpl = cfgLoggerTagsPrefixTmpl + "level"
|
||||
|
||||
// Wallet.
|
||||
|
@ -516,8 +516,8 @@ func fetchLogTagsConfig(v *viper.Viper, defaultLvl zapcore.Level) (map[string]za
|
|||
res := make(map[string]zapcore.Level)
|
||||
|
||||
for i := 0; ; i++ {
|
||||
name := v.GetString(fmt.Sprintf(cfgLoggerTagsNameTmpl, i))
|
||||
if name == "" {
|
||||
tagNames := v.GetString(fmt.Sprintf(cfgLoggerTagsNameTmpl, i))
|
||||
if tagNames == "" {
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -529,7 +529,13 @@ func fetchLogTagsConfig(v *viper.Viper, defaultLvl zapcore.Level) (map[string]za
|
|||
}
|
||||
}
|
||||
|
||||
res[name] = lvl
|
||||
tagNames = strings.TrimSpace(tagNames)
|
||||
for _, tagName := range strings.Split(tagNames, ",") {
|
||||
tagName = strings.TrimSpace(tagName)
|
||||
if len(tagName) != 0 {
|
||||
res[tagName] = lvl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(res) == 0 && !v.IsSet(cfgLoggerTags) {
|
||||
|
|
|
@ -20,8 +20,9 @@ HTTP_GW_LOGGER_SAMPLING_ENABLED=false
|
|||
HTTP_GW_LOGGER_SAMPLING_INITIAL=100
|
||||
HTTP_GW_LOGGER_SAMPLING_THEREAFTER=100
|
||||
HTTP_GW_LOGGER_SAMPLING_INTERVAL=1s
|
||||
HTTP_GW_LOGGER_TAGS_0_NAME=app
|
||||
HTTP_GW_LOGGER_TAGS_1_NAME=datapath
|
||||
HTTP_GW_LOGGER_TAGS_0_NAMES=app,datapath
|
||||
HTTP_GW_LOGGER_TAGS_0_LEVEL=level
|
||||
HTTP_GW_LOGGER_TAGS_1_NAME=external_storage_tree
|
||||
|
||||
HTTP_GW_SERVER_0_ADDRESS=0.0.0.0:443
|
||||
HTTP_GW_SERVER_0_TLS_ENABLED=false
|
||||
|
|
|
@ -30,8 +30,7 @@ logger:
|
|||
thereafter: 100
|
||||
interval: 1s
|
||||
tags:
|
||||
- name: app
|
||||
- name: datapath
|
||||
- names: app,datapath
|
||||
level: debug
|
||||
|
||||
server:
|
||||
|
|
|
@ -176,10 +176,9 @@ logger:
|
|||
thereafter: 100
|
||||
interval: 1s
|
||||
tags:
|
||||
- name: "app"
|
||||
- names: "app,datapath"
|
||||
level: info
|
||||
- name: "datapath"
|
||||
- name: "external_storage_tree"
|
||||
- names: "external_storage_tree"
|
||||
```
|
||||
|
||||
| Parameter | Type | SIGHUP reload | Default value | Description |
|
||||
|
@ -199,14 +198,14 @@ parameter. Available tags:
|
|||
|
||||
```yaml
|
||||
tags:
|
||||
- name: "app"
|
||||
- names: "app,datapath"
|
||||
level: info
|
||||
```
|
||||
|
||||
| Parameter | Type | SIGHUP reload | Default value | Description |
|
||||
|-----------------------|------------|---------------|---------------------------|-------------------------------------------------------------------------------------------------------|
|
||||
| `name` | `string` | yes | | Tag name. 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`. |
|
||||
| Parameter | Type | SIGHUP reload | Default value | Description |
|
||||
|-----------|------------|---------------|---------------------------|-------------------------------------------------------------------------------------------------------|
|
||||
| `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`. |
|
||||
|
||||
### Tag values
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue