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
[logging] add lint-logs.sh to check for newline termination. #12891
Conversation
Suggested by @MarcoFalke here: #12887 (comment) linter hints suggested by @laanwj here: #12887 (comment) |
@@ -63,7 +63,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger { | |||
|
|||
assert(p <= limit); | |||
base[std::min(bufsize - 1, (int)(p - base))] = '\0'; | |||
LogPrintf("leveldb: %s", base); | |||
LogPrintf("leveldb: %s", base); /* Continued */ |
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.
Since you are changing those lines anyway, why not use LogPrintfContinuation
or something?
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.
My suggestion here: #12887 (comment) has inverted semantics. This Continued
here comment indicates that there is a continuation log to follow. LogPrintfContinuation()
would indicate that the log continues a previous log.
I think LogPrintfContinuation()
could be useful, but it's a rebase-the-world PR since it removes the \n
from every call to LogPrintf()
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.
Yes, please don't change every single log message. This solution is fine.
utACK 28682f3354a89f49a402735f94b7f79f34966aab |
utACK 28682f3 |
Very strong concept ACK. Thanks for making this fix persistent by adding a lint script. Please apply this patch to the lint script to make it work as expected: --- lint-logs.sh 2018-04-05 22:43:14.119412169 +0200
+++ lint-logs.sh.fixed 2018-04-05 22:42:03.787354149 +0200
@@ -13,10 +13,10 @@
# ignored
-UNTERMINATED_LOGS=$(git grep "LogPrintf(" -- *cpp | \
- grep -v "\\\n\"" | \
- grep -v "/\* Continued \*/" | \
- grep -v "LogPrintf\(\)")
+UNTERMINATED_LOGS=$(git grep "LogPrintf(" -- "*.cpp" | \
+ grep -v '\\n"' | \
+ grep -v "/\* Continued \*/" | \
+ grep -v "LogPrintf()")
if [[ ${UNTERMINATED_LOGS} != "" ]]; then
echo "All calls to LogPrintf() should be terminated with \\n"
echo The bugs:
ACK modulo fixing the lint script bugs :-) |
Thanks for the review and bugfixes @practicalswift ! Your fixed version caught a non-conforming log, which I've fixed in a new commit. |
utACK 621981530b57ac983b7bf35474c0796fbf5d5ed7 |
1 similar comment
utACK 621981530b57ac983b7bf35474c0796fbf5d5ed7 |
src/wallet/wallet.cpp
Outdated
@@ -3076,7 +3076,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve | |||
wtxNew.fTimeReceivedIsTxTime = true; | |||
wtxNew.fFromMe = true; | |||
|
|||
LogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); | |||
LogPrintf("CommitTransaction:\n%s\n", wtxNew.tx->ToString()); |
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.
Unfortunately this change is wrong, as tx->ToString() adds a final newline: https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.cpp#L99
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.
ah, well spotted. Now fixed.
Incidentally, I hate this log. As far as I'm aware it's the only one with newlines embedded and it confuses my log parser!
Most logs should terminated with a '\n'. Some logs are built up over multiple calls to logPrintf(), so do not need a newline terminater. Comment all of these 'continued' logs as a linter hing.
Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs.
utACK d207207 |
utACK d207207 |
…tion. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
…termination. d207207 [logging] add lint-logs.sh to check for newline termination. (John Newbery) 5c21e6c [logging] Comment all continuing logs. (John Newbery) Pull request description: Check that all calls to LogPrintf() are terminated by a newline, except those that are explicitly marked as 'continued' logs. Tree-SHA512: fe5162b2b2df1e8a4c807da87584fa9af97a6b8377e4090fe0caa136d90bf29a487a123cde94569bdce7101fee3478196d99aa13f1212e24bfe5f41c773604fc
Check that all calls to LogPrintf() are terminated by a newline,
except those that are explicitly marked as 'continued' logs.