Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
20e2a84a
Commit
20e2a84a
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/PRXS-951-Log' into feature/PRXS-951-1984-FindOptions
parents
0d568685
3accb6dd
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
zap/channels.go
+2
-2
2 additions, 2 deletions
zap/channels.go
zap/field.go
+6
-1
6 additions, 1 deletion
zap/field.go
zap/field_test.go
+26
-0
26 additions, 0 deletions
zap/field_test.go
with
34 additions
and
3 deletions
zap/channels.go
+
2
−
2
View file @
20e2a84a
...
@@ -16,7 +16,7 @@ const (
...
@@ -16,7 +16,7 @@ const (
func
ContainsChannels
(
channels
...
string
)
FilterFunc
{
func
ContainsChannels
(
channels
...
string
)
FilterFunc
{
return
func
(
entry
zapcore
.
Entry
,
fields
[]
zapcore
.
Field
)
bool
{
return
func
(
entry
zapcore
.
Entry
,
fields
[]
zapcore
.
Field
)
bool
{
for
_
,
f
:=
range
fields
{
for
_
,
f
:=
range
fields
{
if
f
.
Key
==
channelKey
&&
f
.
Type
==
zapcore
.
ArrayMarshaler
Type
{
if
f
.
Key
==
channelKey
&&
f
.
Type
==
zapcore
.
Skip
Type
{
for
_
,
v
:=
range
f
.
Interface
.
(
stringArray
)
{
for
_
,
v
:=
range
f
.
Interface
.
(
stringArray
)
{
if
data
.
Contains
(
v
,
channels
)
{
if
data
.
Contains
(
v
,
channels
)
{
return
true
return
true
...
@@ -34,7 +34,7 @@ func WithDefaultChannel(core zapcore.Core, channel string) zapcore.Core {
...
@@ -34,7 +34,7 @@ func WithDefaultChannel(core zapcore.Core, channel string) zapcore.Core {
return
WithChannel
(
core
,
channel
,
true
)
return
WithChannel
(
core
,
channel
,
true
)
}
}
// WithChannel добавляет к переданному Core фильтрацию записей по каналам.
// WithChannel добавляет к переданному
zapcore.
Core фильтрацию записей по каналам.
// Это означает, что если запись содержит поле Channels и значение соответствует
// Это означает, что если запись содержит поле Channels и значение соответствует
// переданному каналу, то запись будет передана в zapcore.Core.
// переданному каналу, то запись будет передана в zapcore.Core.
func
WithChannel
(
core
zapcore
.
Core
,
channel
string
,
isDefault
...
bool
)
zapcore
.
Core
{
func
WithChannel
(
core
zapcore
.
Core
,
channel
string
,
isDefault
...
bool
)
zapcore
.
Core
{
...
...
This diff is collapsed.
Click to expand it.
zap/field.go
+
6
−
1
View file @
20e2a84a
...
@@ -19,8 +19,13 @@ func (ss stringArray) MarshalLogArray(arr zapcore.ArrayEncoder) error {
...
@@ -19,8 +19,13 @@ func (ss stringArray) MarshalLogArray(arr zapcore.ArrayEncoder) error {
return
nil
return
nil
}
}
// Channels возвращает поле, содержащее список каналов, в которые должна быть передана запись.
func
Channels
(
channels
...
string
)
zap
.
Field
{
func
Channels
(
channels
...
string
)
zap
.
Field
{
return
zap
.
Array
(
channelKey
,
stringArray
(
channels
))
return
zap
.
Field
{
Key
:
channelKey
,
Type
:
zapcore
.
SkipType
,
// используем тип zapcore.SkipType, чтобы при кодировании поле игнорировалось
Interface
:
stringArray
(
channels
),
}
}
}
func
Category
(
category
string
)
zap
.
Field
{
func
Category
(
category
string
)
zap
.
Field
{
...
...
This diff is collapsed.
Click to expand it.
zap/field_test.go
+
26
−
0
View file @
20e2a84a
...
@@ -10,8 +10,34 @@ import (
...
@@ -10,8 +10,34 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/users"
"git.perx.ru/perxis/perxis-go/pkg/users"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
)
func
TestChannels
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
field
zap
.
Field
want
zap
.
Field
}{
{
name
:
"ok"
,
field
:
Channels
(
"master"
),
want
:
zap
.
Field
{
Key
:
channelKey
,
Type
:
zapcore
.
SkipType
,
Interface
:
stringArray
{
"master"
}}},
{
name
:
"invalid"
,
field
:
Channels
(),
want
:
zap
.
Field
{
Key
:
channelKey
,
Type
:
zapcore
.
SkipType
,
Interface
:
stringArray
(
nil
)}},
}
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
tc
.
want
,
tc
.
field
)
})
}
}
func
TestChannelsEncode
(
t
*
testing
.
T
)
{
enc
:=
zapcore
.
NewMapObjectEncoder
()
field
:=
Channels
(
"master"
)
field
.
AddTo
(
enc
)
assert
.
Empty
(
t
,
enc
.
Fields
)
}
func
TestCategory
(
t
*
testing
.
T
)
{
func
TestCategory
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment