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
d77d6bc1
Commit
d77d6bc1
authored
1 year ago
by
Semyon Krestyaninov
Browse files
Options
Downloads
Patches
Plain Diff
Revert "refactor"
This reverts commit
29d881cf
.
parent
29d881cf
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
log/zap/core.go
+17
-16
17 additions, 16 deletions
log/zap/core.go
log/zap/field.go
+2
-2
2 additions, 2 deletions
log/zap/field.go
log/zap/field_test.go
+1
-1
1 addition, 1 deletion
log/zap/field_test.go
with
20 additions
and
19 deletions
log/zap/core.go
+
17
−
16
View file @
d77d6bc1
...
...
@@ -57,6 +57,11 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent
fields
=
append
(
fields
,
core
.
fields
...
)
}
enc
:=
zapcore
.
NewMapObjectEncoder
()
for
_
,
field
:=
range
fields
{
field
.
AddTo
(
enc
)
}
ent
:=
&
log
.
Entry
{
ID
:
id
.
GenerateNewID
(),
Timestamp
:
entry
.
Time
,
...
...
@@ -64,22 +69,18 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent
Message
:
entry
.
Message
,
}
for
_
,
field
:=
range
fields
{
switch
field
.
Key
{
case
"category"
:
ent
.
Category
=
field
.
String
case
"component"
:
ent
.
Component
=
field
.
String
case
"event"
:
ent
.
Event
=
field
.
String
case
"object"
:
ent
.
ObjectID
=
field
.
Interface
.
(
*
oid
.
ObjectId
)
case
"caller"
:
ent
.
CallerID
=
field
.
Interface
.
(
*
oid
.
ObjectId
)
case
"attr"
:
ent
.
Attr
=
field
.
Interface
case
"tags"
:
ent
.
Tags
,
_
=
field
.
Interface
.
([]
string
)
ent
.
Category
,
_
=
enc
.
Fields
[
"category"
]
.
(
string
)
ent
.
Component
,
_
=
enc
.
Fields
[
"component"
]
.
(
string
)
ent
.
Event
,
_
=
enc
.
Fields
[
"event"
]
.
(
string
)
ent
.
ObjectID
,
_
=
enc
.
Fields
[
"object"
]
.
(
*
oid
.
ObjectId
)
ent
.
CallerID
,
_
=
enc
.
Fields
[
"caller"
]
.
(
*
oid
.
ObjectId
)
ent
.
Attr
=
enc
.
Fields
[
"attr"
]
if
tags
,
ok
:=
enc
.
Fields
[
"tags"
]
.
([]
any
);
ok
{
for
_
,
item
:=
range
tags
{
if
tag
,
ok
:=
item
.
(
string
);
ok
{
ent
.
Tags
=
append
(
ent
.
Tags
,
tag
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
log/zap/field.go
+
2
−
2
View file @
d77d6bc1
...
...
@@ -62,12 +62,12 @@ func Attr(attr any) zap.Field {
if
attr
==
nil
{
return
zap
.
Skip
()
}
return
zap
.
Reflect
(
"attr"
,
attr
)
return
zap
.
Any
(
"attr"
,
attr
)
}
func
Tags
(
tags
...
string
)
zap
.
Field
{
if
len
(
tags
)
==
0
{
return
zap
.
Skip
()
}
return
zap
.
Reflect
(
"tags"
,
tags
)
return
zap
.
Strings
(
"tags"
,
tags
)
}
This diff is collapsed.
Click to expand it.
log/zap/field_test.go
+
1
−
1
View file @
d77d6bc1
...
...
@@ -173,7 +173,7 @@ func TestTags(t *testing.T) {
field
zap
.
Field
want
zap
.
Field
}{
{
name
:
"ok"
,
field
:
Tags
(
"a"
,
"b"
,
"c"
),
want
:
zap
.
Reflect
(
"tags"
,
[]
string
{
"a"
,
"b"
,
"c"
})},
{
name
:
"ok"
,
field
:
Tags
(
"a"
,
"b"
,
"c"
),
want
:
zap
.
Strings
(
"tags"
,
[]
string
{
"a"
,
"b"
,
"c"
})},
{
name
:
"invalid"
,
field
:
Tags
(
nil
...
),
want
:
zap
.
Skip
()},
}
...
...
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