-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 log record IDs #29355
Fix log record IDs #29355
Conversation
I think that this is ready to go now, but I do have a concern about the implementation as it stands now. Suppose that some package has a function like this: function f()
for i in 1:1_000_000
@info "Working"
end
@info "Done"
end An application might want to filter out the "Working" logs, but pass along the "Done" log to the user. Prior to this PR, there was no good way to do that, but now the application can filter based on the log record ID, and everything works. Yay! But now suppose that the package is modified to add a new log: function f()
@info "Starting"
for i in 1:1_000_000
@info "Working"
end
@info "Done"
end Now the application will actually filter out the "Starting" log, and the user will be flooded with "Working" logs. One solution would be to include the message in the hash to compute the ID, but this would mean that the message (which may be expensive) would need to be computed before the |
Bump. It would be great if this could make it in to v1.0.1. |
1.0.1 is frozen. Can go into 1.0.2 |
Except if you do something like:
And I can see that code being written by a lot of people who don't know about logs now taking kwarguments, or even those who do, but think that interpolation is prettier. |
I'm not really sure what you are arguing for? With this PR, every log record generated by your code with have the same ID, and the Though the example you provide is another example of why including the message in the original id hash is a bad idea. |
Can this please get a backport label so it doesn't get lost? |
I misread something in the code. I wish I understood why this feature worked in 0.7-beta without having this code. |
@@ -311,12 +315,12 @@ function logmsg_code(_module, file, line, level, message, exs...) | |||
_module = $_module | |||
logger = current_logger_for_env(std_level, group, _module) | |||
if !(logger === nothing) | |||
file = $file |
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.
Why were these moved?
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.
Those values are needed to compute id
.
Oh, you're right there's a very serious problem with id's in 1.0. Not only are they not stable, but they're computed at every log invocation (very expensive, and will explode the log id storage!) @oxinabox this was broken by the fix in f0e1d21 which went in very shortly before 1.0 (and fixed a quite legitimate bug, but edge case). Apparently my tests didn't cover this and I've been absent from the logging discussion for a few months, sorry (new job, etc etc...). Hmm what to do. So I'm sure this PR is part of the solution, but I'm not sure it's quite right yet. I'm thinking that automatically computed So what about if we go back to using the |
Glad to have you back then! Yes, I think we knew we were rushing in a few fixes to this code that weren't 100% solid, but seemed not to be breaking anything (as you say, "part of the solution, but ... not quite right yet"). Perhaps we need more of that "memoized run-time execution" code sprinkled in here too (#28289)? |
Thanks! I hope I'm back for a while... we'll see. The memoization trick is a really clever and relatively nice way around the bootstrap problems with Also regarding memoization, are there any problems with multithreading which could arise from that? Is it reasonable to assume pointer sized stores are atomic on all platforms we support? |
Anyway, back to the issue at hand. For the particular case of Thinking back, what I was trying to achieve with making Putting that all together, I think we should go back to simply hashing the (full) syntax of the log statement, combined with the module from the |
I've made a branch with my preferred fix (cjf/fix-logging-ids) I just haven't had the time to add additional tests. [edit] Actually my branch runs into bootstrap issues which I'll need to chase down. We might need the memoization trick again to solve that problem. |
Feel free to take the tests from this PR. |
Thanks, I cherry picked your commit containing the tests already :-) |
Closing in favor of #29878. |
* fix bug and add tests * Reinstate statically computed log record ids Log ids are meant to identify the location of the message in the source code and must be computed at compile time. fix #28786, fix #28400; closes #29355. * Clarify documentation regarding log record `id` (cherry picked from commit 51683c4)
* fix bug and add tests * Reinstate statically computed log record ids Log ids are meant to identify the location of the message in the source code and must be computed at compile time. fix #28786, fix #28400; closes #29355. * Clarify documentation regarding log record `id` (cherry picked from commit 51683c4)
* fix bug and add tests * Reinstate statically computed log record ids Log ids are meant to identify the location of the message in the source code and must be computed at compile time. fix #28786, fix #28400; closes #29355. * Clarify documentation regarding log record `id` (cherry picked from commit 51683c4)
* fix bug and add tests * Reinstate statically computed log record ids Log ids are meant to identify the location of the message in the source code and must be computed at compile time. fix #28786, fix #28400; closes #29355. * Clarify documentation regarding log record `id` (cherry picked from commit 51683c4)
This PR ensures that a given log statement will always produce the same ID. It is actually a bit tricky to implement because the ID should "uniquely identify the source location in the originating module, but should be stable across versions of the originating module, provided the log generating statement itself doesn't change" (according to the source).
This definitely needs some tests so that this doesn't break again.
Closes #28786.