-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix caller in logs #1176
Fix caller in logs #1176
Conversation
Signed-off-by: Lukas Zapletal <[email protected]>
cmd/image-builder/logging.go
Outdated
} | ||
if e.Context.Value(common.LoggingFrameCtx) != nil { | ||
frame := e.Context.Value(common.LoggingFrameCtx).(runtime.Frame) | ||
e.Caller = &frame |
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.
I'm not the golang expert - is this safe to return this pointer?
although the implementation of logrus does the same - it feels bad :-|
6873ae1
to
bf2ad38
Compare
|
||
const ( | ||
LoggingFrameCtx ctxKey = iota | ||
) |
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.
It is a good practice not to export context key types and values so other packages cannot modify the values. Here it is a mix - you export the value but not the type.
Yeah I noticed this as well. Tho the implementation seems fragile, creating a context value per request is fine, but per log entry? There can be many log entries per request, this could get out of control. Cannot you modify the caller on the fly directly? Or even better - turn off automatic caller adding and implement your own hook that will consider this wrapper instead. Whatever you do, please make a unit test for this, do some logging directly through |
Note: related implementation: osbuild/osbuild-composer#4132 |
This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 30+7 days with no activity. |
@lzap based on your #1174 I'd like to add the fix to show the correct caller (for the cases using
echo_logrus.go
)I'd keep this as draft until yours is merged
Do you think this makes sense?
example log message is (just added some newlines for readabililaty)
before:
after: