Skip to content
Snippets Groups Projects
Commit 18858016 authored by Semyon Krestyaninov's avatar Semyon Krestyaninov
Browse files

refactor ContainsChannels and Channel field

parent ac5b5d39
No related branches found
No related tags found
No related merge requests found
package zap
import (
"strings"
"git.perx.ru/perxis/perxis-go/pkg/data"
"go.uber.org/zap/zapcore"
)
......@@ -18,9 +16,8 @@ const (
func ContainsChannels(channels ...string) FilterFunc {
return func(entry zapcore.Entry, fields []zapcore.Field) bool {
for _, f := range fields {
if f.Key == channelKey && f.Type == zapcore.StringType {
list := strings.Split(f.String, ",")
for _, v := range list {
if f.Key == channelKey && f.Type == zapcore.ArrayMarshalerType {
for _, v := range f.Interface.(stringArray) {
if data.Contains(v, channels) {
return true
}
......
......@@ -2,16 +2,25 @@ package zap
import (
"context"
"strings"
"git.perx.ru/perxis/perxis-go/id"
_ "git.perx.ru/perxis/perxis-go/id/system" // регистрируем обработчики для системных объектов
"git.perx.ru/perxis/perxis-go/pkg/auth"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type stringArray []string
func (ss stringArray) MarshalLogArray(arr zapcore.ArrayEncoder) error {
for i := range ss {
arr.AppendString(ss[i])
}
return nil
}
func Channels(channels ...string) zap.Field {
return zap.String(channelKey, strings.Join(channels, ","))
return zap.Array(channelKey, stringArray(channels))
}
func Category(category string) zap.Field {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment