-
Notifications
You must be signed in to change notification settings - Fork 0
Logging v2 #25
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
Merged
Merged
Logging v2 #25
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6b48350
feat: implement a basic of new logutil
yorukot 09ec6ee
feat: mark database warp as deprecated
yorukot e046ff2
feat: finish a new version of logutil and update pkg docs
yorukot 352cfeb
refactor: remove unused function
yorukot f224834
feat: add example
yorukot a42be17
feat: add warp info error and rename example to examples
yorukot b6e2e32
feat: add deprecated function back
yorukot b9dede9
feat: update flow to more approch the best practice
yorukot 8a1e76c
feat(log): improve structured error logging
yorukot b86b0e9
feat: keep legacy db error wrappers logging without deprecation marks
YukinaMochizuki 245bb7d
Merge branch 'main' into logging-v2
YukinaMochizuki 4549ba4
test(log): pass a typed nil context in SetupFlow tests
YukinaMochizuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| errutil "github.com/NYCU-SDC/summer/pkg/error" | ||
| logutil "github.com/NYCU-SDC/summer/pkg/log" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| func main() { | ||
| logger := zap.NewExample() | ||
|
|
||
| ctx, eventLogger := logutil.SetupFlow( | ||
| context.Background(), | ||
| logger, | ||
| "user.create", | ||
| zap.String("request.id", "req-7"), | ||
| zap.String("enduser.id", "user-42"), | ||
| zap.String("service.name", "account-api"), | ||
| ) | ||
| eventLogger = logutil.WithEventOutcome(logutil.EventOutcomeFailure, eventLogger) | ||
|
|
||
| ctx = logutil.WithErrorType(ctx, errutil.ALREADY_EXISTS) | ||
| ctx = logutil.WithReason(ctx, "duplicate_email") | ||
|
|
||
| baseErr := errors.New("email already exists") | ||
|
|
||
| // Wrap the error when it needs to carry detail to the logging layer. | ||
| err := errutil.WrapInfoError(baseErr, map[errutil.ErrorInfoKey]any{ | ||
| errutil.ErrorInfoOperation: "create_user", | ||
| errutil.ErrorInfoField: "email", | ||
| errutil.ErrorInfoRetryable: false, | ||
| }) | ||
|
|
||
| logutil.Error(ctx, eventLogger, "create user rejected", err, zap.String("email.domain", "example.com")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.