-
-
Couldn't load subscription status.
- Fork 4.1k
Fix slog logger caller frame detection to output correct source file #7610
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
base: master
Are you sure you want to change the base?
Conversation
|
Correct stack-frame resolution for Fixes incorrect file/line attribution in Key Changes• Added Affected Areas• This summary was automatically generated by @propel-code-bot |
|
Hi, @jinzhu @rezamokaram. could you please review this PR? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where the slog logger was reporting incorrect source file locations in log output. Instead of showing the actual caller's location, it was incorrectly displaying GORM's internal slog.go file.
Key Changes:
- Refactored
FileWithLineNum()to extract frame detection logic into a reusableCallerFrame()function - Modified slog logger to use
CallerFrame()when creating log records, ensuring accurate source location reporting - Added test coverage to verify that slog output correctly shows test file locations instead of internal GORM files
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| utils/utils.go | Extracted CallerFrame() function to return the actual caller's runtime frame, enabling reuse across logging implementations |
| logger/slog.go | Implemented custom log() method that uses CallerFrame().PC to set accurate source locations in slog records |
| logger/slog_test.go | Added test to verify slog output contains correct caller file reference and excludes internal GORM files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
补充下,slog是分前端(logger), 后端Handler, 官方设计logger是可以按需修改, Handler复用,这里通过NewRecord通过Handler处理也是比较符合社区设计的 |
What did this pull request do?
close #7609
User Case Description