Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for ctx keys feature of package glog #3273

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/os/log/ctx_keys/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logger:
Level: "all"
Stdout: true
CtxKeys: ["RequestId", "UserId"]
20 changes: 20 additions & 0 deletions example/os/log/ctx_keys/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

package main
gqcn marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"

"github.com/gogf/gf/v2/frame/g"
)

func main() {
var ctx = context.Background()
ctx = context.WithValue(ctx, "RequestId", "123456789")
ctx = context.WithValue(ctx, "UserId", "10000")
g.Log().Error(ctx, "runtime error")
}
1 change: 1 addition & 0 deletions util/gvalid/gvalid_validator_check_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Erro
}
// The error should have error code that is `gcode.CodeValidationFailed`.
if gerror.Code(err) == gcode.CodeNil {
// TODO it's better using interface?
if e, ok := err.(*gerror.Error); ok {
e.SetCode(gcode.CodeValidationFailed)
}
Expand Down