Skip to content

Commit 3190785

Browse files
committed
Merge #12891: [logging] add lint-logs.sh to check for newline 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
2 parents d6f10b2 + d207207 commit 3190785

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

contrib/devtools/lint-logs.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2018 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Check that all logs are terminated with '\n'
8+
#
9+
# Some logs are continued over multiple lines. They should be explicitly
10+
# commented with \* Continued *\
11+
#
12+
# There are some instances of LogPrintf() in comments. Those can be
13+
# ignored
14+
15+
16+
UNTERMINATED_LOGS=$(git grep "LogPrintf(" -- "*.cpp" | \
17+
grep -v '\\n"' | \
18+
grep -v "/\* Continued \*/" | \
19+
grep -v "LogPrintf()")
20+
if [[ ${UNTERMINATED_LOGS} != "" ]]; then
21+
echo "All calls to LogPrintf() should be terminated with \\n"
22+
echo
23+
echo "${UNTERMINATED_LOGS}"
24+
exit 1
25+
fi

src/dbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {
6363

6464
assert(p <= limit);
6565
base[std::min(bufsize - 1, (int)(p - base))] = '\0';
66-
LogPrintf("leveldb: %s", base);
66+
LogPrintf("leveldb: %s", base); /* Continued */
6767
if (base != buffer) {
6868
delete[] base;
6969
}

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ bool AppInitMain()
12331233

12341234
// Warn about relative -datadir path.
12351235
if (gArgs.IsArgSet("-datadir") && !fs::path(gArgs.GetArg("-datadir", "")).is_absolute()) {
1236-
LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the "
1236+
LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
12371237
"current working directory '%s'. This is fragile, because if bitcoin is started in the future "
12381238
"from a different location, it will be unable to locate the current data files. There could "
12391239
"also be data loss if bitcoin is started while in a temporary directory.\n",

src/sync.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
8181
LogPrintf("Previous lock order was:\n");
8282
for (const std::pair<void*, CLockLocation> & i : s2) {
8383
if (i.first == mismatch.first) {
84-
LogPrintf(" (1)");
84+
LogPrintf(" (1)"); /* Continued */
8585
}
8686
if (i.first == mismatch.second) {
87-
LogPrintf(" (2)");
87+
LogPrintf(" (2)"); /* Continued */
8888
}
8989
LogPrintf(" %s\n", i.second.ToString());
9090
}
9191
LogPrintf("Current lock order is:\n");
9292
for (const std::pair<void*, CLockLocation> & i : s1) {
9393
if (i.first == mismatch.first) {
94-
LogPrintf(" (1)");
94+
LogPrintf(" (1)"); /* Continued */
9595
}
9696
if (i.first == mismatch.second) {
97-
LogPrintf(" (2)");
97+
LogPrintf(" (2)"); /* Continued */
9898
}
9999
LogPrintf(" %s\n", i.second.ToString());
100100
}

src/txdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ bool CCoinsViewDB::Upgrade() {
370370

371371
int64_t count = 0;
372372
LogPrintf("Upgrading utxo-set database...\n");
373-
LogPrintf("[0%%]...");
373+
LogPrintf("[0%%]..."); /* Continued */
374374
uiInterface.ShowProgress(_("Upgrading UTXO database"), 0, true);
375375
size_t batch_size = 1 << 24;
376376
CDBBatch batch(db);
@@ -389,7 +389,7 @@ bool CCoinsViewDB::Upgrade() {
389389
uiInterface.ShowProgress(_("Upgrading UTXO database"), percentageDone, true);
390390
if (reportDone < percentageDone/10) {
391391
// report max. every 10% step
392-
LogPrintf("[%d%%]...", percentageDone);
392+
LogPrintf("[%d%%]...", percentageDone); /* Continued */
393393
reportDone = percentageDone/10;
394394
}
395395
}

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,13 +2230,13 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
22302230
DoWarning(strWarning);
22312231
}
22322232
}
2233-
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__,
2233+
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, /* Continued */
22342234
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
22352235
log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
22362236
FormatISO8601DateTime(pindexNew->GetBlockTime()),
22372237
GuessVerificationProgress(chainParams.TxData(), pindexNew), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
22382238
if (!warningMessages.empty())
2239-
LogPrintf(" warning='%s'", boost::algorithm::join(warningMessages, ", "));
2239+
LogPrintf(" warning='%s'", boost::algorithm::join(warningMessages, ", ")); /* Continued */
22402240
LogPrintf("\n");
22412241

22422242
}
@@ -3902,14 +3902,14 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
39023902
int nGoodTransactions = 0;
39033903
CValidationState state;
39043904
int reportDone = 0;
3905-
LogPrintf("[0%%]...");
3905+
LogPrintf("[0%%]..."); /* Continued */
39063906
for (CBlockIndex* pindex = chainActive.Tip(); pindex && pindex->pprev; pindex = pindex->pprev)
39073907
{
39083908
boost::this_thread::interruption_point();
39093909
int percentageDone = std::max(1, std::min(99, (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
39103910
if (reportDone < percentageDone/10) {
39113911
// report every 10% step
3912-
LogPrintf("[%d%%]...", percentageDone);
3912+
LogPrintf("[%d%%]...", percentageDone); /* Continued */
39133913
reportDone = percentageDone/10;
39143914
}
39153915
uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone, false);

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
30753075
wtxNew.fTimeReceivedIsTxTime = true;
30763076
wtxNew.fFromMe = true;
30773077

3078-
LogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString());
3078+
LogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); /* Continued */
30793079
{
30803080
// Take key pair from key pool so it won't be used again
30813081
reservekey.KeepKey();

0 commit comments

Comments
 (0)