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
bcfc1646
Commit
bcfc1646
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
fa2242c6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/log/zap/field.go
+11
-7
11 additions, 7 deletions
pkg/log/zap/field.go
with
11 additions
and
7 deletions
pkg/log/zap/field.go
+
11
−
7
View file @
bcfc1646
...
@@ -43,16 +43,12 @@ func Object(v any) zapcore.Field {
...
@@ -43,16 +43,12 @@ func Object(v any) zapcore.Field {
type
callerKey
struct
{}
type
callerKey
struct
{}
// ContextWithCaller добавляет передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// ContextWithCaller добавляет
в контекст
передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// Поддерживает один из типов: string, fmt.Stringer. Если передан аргумент другого типа, в качестве вызывающего
// Поддерживает один из типов: string, fmt.Stringer. Если передан аргумент другого типа, в качестве вызывающего
// будет установлен "unknown".
// будет установлен "unknown".
func
ContextWithCaller
(
parent
context
.
Context
,
caller
any
)
context
.
Context
{
func
ContextWithCaller
(
parent
context
.
Context
,
v
any
)
context
.
Context
{
return
context
.
WithValue
(
parent
,
callerKey
{},
caller
)
}
func
CallerFromContext
(
ctx
context
.
Context
)
zapcore
.
Field
{
var
caller
string
var
caller
string
switch
value
:=
ctx
.
Value
(
callerKey
{})
.
(
type
)
{
switch
value
:=
v
.
(
type
)
{
case
string
:
case
string
:
caller
=
value
caller
=
value
case
fmt
.
Stringer
:
case
fmt
.
Stringer
:
...
@@ -60,6 +56,14 @@ func CallerFromContext(ctx context.Context) zapcore.Field {
...
@@ -60,6 +56,14 @@ func CallerFromContext(ctx context.Context) zapcore.Field {
default
:
default
:
caller
=
unknownCaller
caller
=
unknownCaller
}
}
return
context
.
WithValue
(
parent
,
callerKey
{},
caller
)
}
func
CallerFromContext
(
ctx
context
.
Context
)
zapcore
.
Field
{
caller
,
ok
:=
ctx
.
Value
(
callerKey
{})
.
(
string
)
if
!
ok
{
caller
=
unknownCaller
}
return
zap
.
String
(
"caller"
,
caller
)
return
zap
.
String
(
"caller"
,
caller
)
}
}
...
...
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