-
Notifications
You must be signed in to change notification settings - Fork 38.7k
log: Prefix log messages with function name and source code location if -logsourcelocations is set #19809
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Concept ACK |
|
Concept ACK. After this we can start removing the explicit |
promag
left a comment
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.
Concept ACK.
Use in test framework?
|
Concept ACK, will review in the next few days |
|
Code review and tested ACK bd71653bfc312b10ca6b578b7c3accd0155b1a20 Edit: I somewhat wonder how much larger this makes the executable. This adds a string for every function that has logging. I don't think it's too bad, but will test. |
|
Ooh, concept ACK |
|
Wouldn't hurt I think to have this active for a single test at least? |
theStack
left a comment
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.
Tested ACK bd71653bfc312b10ca6b578b7c3accd0155b1a20 🧪
Note that in some cases the showed function name is quite generic and doesn't prevent the need for grepping contents of the message (as elaborated in the PR description), that is when LogPrint{f} is called in another logging wrapper function (e.g. WalletLogPrintf(...), Timer::Log(...) or ArgsManager::logArgsPrefix(...)).
Still an incredibly useful feature though that will save devs plenty of time in the future for sure!
|
It seems I'll be in a minority here, but I don't think this is very useful in the current form. If the goal is to avoid the need for searching the source code to find where a message originated, it would be better to include file/line number instead of (or at least in addition to) the function name. Function names can be ambiguous, and do occasionally move from one file to another, so just that still means you need to grep the source code to find where the function is. |
|
@sipa: Agreed that the PR doesn't eliminate the need to grep completely, but I think the main focus is to get rid of the burdensome part of figuring out what to grep in the first place (as expressed in the PR description "try to figure out a regexp matching the static part of the dynamic log message"). That can sometimes take quite some iterations or is not even possible at all of the log message is assembled in a highly dynamic way (i.e. lots of %s in the log format string). Also, the function name grep is more effective as it not only shows you in which function the log is printed (single result), but also already at which places this function is declared/defined and called. For my purposes thats quite a lot of useful information about the causes of a log message after a single no-brainer grep considering I didn't even need to open a file yet at this point :) That said, also showing file and line number can for sure also be helpful. Maybe via verbosity levels? |
That's a good point, I had missed this. I think it can be partially addressed with just better log messages, but this PR is a useful catch-all improvement with little code changes. |
4be7635 to
791facc
Compare
Now enabled for the unit tests and the functional tests.
I think that should be a separate option ( |
b9a2c64 to
b0287dc
Compare
theStack
left a comment
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.
ACK b0287dc4fa83e5d3c95edbf9bc120e222f9e1a22
Verified that since my last tested ACK, another commit has been added that activates the feature for unit tests, and for functional tests starting with 0.21.0 (minimum is set to 0.20.99 to also enable it on the master branch before the 0.21.0 release) 👌
|
Anything left to do here? :) |
49487d3 to
8cbeb9e
Compare
|
Rebased and bumped version check :) |
|
Concept ACK |
theStack
left a comment
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.
re-ACK 8cbeb9ec8650d6fe25afaae8b2a5f91aab00f2f7 🏞️
|
Concept ACK, if only to remove the |
maflcko
left a comment
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.
ACK 8cbeb9ec8650d6fe25afaae8b2a5f91aab00f2f7
Wouldn't it be slightly better to also include the line number (or filename and line) as well then? |
|
@practicalswift Mind replying to the open questions in any way? Would be good to make progress here. |
8cbeb9e to
9f5fc7e
Compare
Sure, that's a good idea but that would be out of scope for A follow-up PR can add say |
Having two options seems like overkill; why not make this one introduce |
|
review ACK 9f5fc7eb55f8a19f6002f4cfe92e76c574ee8749 I am also ok with printing the file:line as well when |
Being the very flexible person I am I have now added the Live demo: Please re-review! :) |
|
review ACK 09b974587ff90834c3559c15b3ab7d9489c65d65 |
ajtowns
left a comment
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.
ACK 09b974587ff90834c3559c15b3ab7d9489c65d65 -- minimal testing only
For functions defined in header files, I'm seeing these logged as
2021-01-15T06:44:32Z [./util/system.h:449] [TraceThread] torcontrol thread start
with a leading "./" -- might be due to us using #include <> which implies an include path search?
btcslade
left a comment
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.
ACK 09b974587ff90834c3559c15b3ab7d9489c65d65
09b9745 to
b4511e2
Compare
|
Thanks for reviewing!
Now removing leading
Please re-review :) |
maflcko
left a comment
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.
review ACK b4511e2 🌃
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK b4511e2e2ed1a6077ae6826a9ee6b7a311293d08 🌃
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgUpQv+KjsWdQmlTRct27nvZGqCCHtsB6PCiZiAO9uywglBEBu6cTsDnGsVnH3h
EyJYPc2a19PaY8MH8uocTrR7owPl7TgqaufvhFPWd63pkg6WLk3W9R+eot//mOFV
za90hjk8oexnnPxaREWqXLJh7qQxNwYhGirpOdQ+gId35a5y/qYPumaPN97oZTQg
7xU85Ik2V+kAdD7y/6qUfB82ZRlwjfirSl9MdctznaXsaQLuQoGbkSdoliZNdl8e
D6xCplsSq7Sxy8cLnzpKHeX/7ouZTv/yeeLRD874kJX/CLzij2x5Pg7Hs2dnCT9f
zoq8Nu1BR9O2hoRf7rKbJva4tZBOHUKdmDOeUX8ozkwmcA8U2YMBr0Y6QvZZJX8H
QvDpkV513nUAj2BjjLxQOAkJAwi+hCcQu8LWJVN+BMD6iTZ6IJ0zJws8bdXCq4Fk
ernWM0gjqDfpaDy4O3Ita+MQsKS9ylM5ojjMKBKG+XJdZiC8vqjbDq4cXPtJ9E1x
HLVdMr8S
=ezwm
-----END PGP SIGNATURE-----
Timestamp of file with hash 1aea386739b0674d3af7837475dd6afb7545a269fc384634b14a41a5d3a0d80d -
|
Code review ACK b4511e2 |
…source code location if -logsourcelocations is set b4511e2 log: Prefix log messages with function name if -logsourcelocations is set (practicalswift) Pull request description: Prefix log messages with function name if `-logfunctionnames` is set. Yes, exactly like `-logthreadnames` but for function names instead of thread names :) This is a small developer ergonomics improvement: I've found this to be a cheap/simple way to correlate log output and originating function. For me it beats the ordinary cycle of 1.) try to figure out a regexp matching the static part of the dynamic log message, 2.) `git grep -E 'Using .* MiB out of .* requested for signature cache'`, 3.) `mcedit filename.cpp` (`openemacs filename.cpp` works too!) and 4.) search for log message and scroll up to find the function name :) Without any logging parameters: ``` $ src/bitcoind -regtest 2020-08-25T03:29:04Z Using RdRand as an additional entropy source 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z block tree size = 1 2020-08-25T03:29:04Z nBestHeight = 0 2020-08-25T03:29:04Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z 0 addresses found from DNS seeds ``` With `-logthreadnames` and `-logfunctionnames`: ``` $ src/bitcoind -regtest -logthreadnames -logfunctionnames 2020-08-25T03:29:04Z [init] [ReportHardwareRand] Using RdRand as an additional entropy source 2020-08-25T03:29:04Z [init] [InitSignatureCache] Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [InitScriptExecutionCache] Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2020-08-25T03:29:04Z [init] [LoadChainTip] Loaded best chain: hashBestChain=0fff88f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22ff height=0 date=2011-02-02T23:16:42Z progress=1.000000 2020-08-25T03:29:04Z [init] [AppInitMain] block tree size = 1 2020-08-25T03:29:04Z [init] [AppInitMain] nBestHeight = 0 2020-08-25T03:29:04Z [loadblk] [LoadMempool] Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 2020-08-25T03:29:04Z [dnsseed] [ThreadDNSAddressSeed] 0 addresses found from DNS seeds ``` ACKs for top commit: laanwj: Code review ACK b4511e2 MarcoFalke: review ACK b4511e2 🌃 Tree-SHA512: d100f5364630c323f31d275259864c597f7725e462d5f4bdedcc7033ea616d7fc0d16ef1b2af557e692f4deea73c6773ccfc681589e7bf6ba970b9ec169040c7
… set Summary: > Prefix log messages with function name if `-logfunctionnames` is set, exactly like `-logthreadnames but for function names instead of thread names. > > This is a small developer ergonomics improvement: I've found this to be a cheap/simple way to correlate log output and originating function. This is a backport of [[bitcoin/bitcoin#19809 | core#19809]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10951
Prefix log messages with function name if
-logfunctionnamesis set.Yes, exactly like
-logthreadnamesbut for function names instead of thread names :)This is a small developer ergonomics improvement: I've found this to be a cheap/simple way to correlate log output and originating function.
For me it beats the ordinary cycle of 1.) try to figure out a regexp matching the static part of the dynamic log message, 2.)
git grep -E 'Using .* MiB out of .* requested for signature cache', 3.)mcedit filename.cpp(openemacs filename.cppworks too!) and 4.) search for log message and scroll up to find the function name :)Without any logging parameters:
With
-logthreadnamesand-logfunctionnames: