diff --git a/src/addrman.cpp b/src/addrman.cpp index 9c3a24db900..5cd1d41fd9a 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -1055,7 +1055,7 @@ void AddrManImpl::Check() const const int err{CheckAddrman()}; if (err) { - LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err); + LogError("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err); assert(false); } } diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index cb9abee563f..608f61f07c6 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -47,8 +47,8 @@ static void HandleError(const leveldb::Status& status) if (status.ok()) return; const std::string errmsg = "Fatal LevelDB error: " + status.ToString(); - LogPrintf("%s\n", errmsg); - LogPrintf("You can use -debug=leveldb to get more complete diagnostic messages\n"); + LogError("%s", errmsg); + LogInfo("You can use -debug=leveldb to get more complete diagnostic messages"); throw dbwrapper_error(errmsg); } @@ -309,7 +309,7 @@ std::optional CDBWrapper::ReadImpl(std::span key) if (!status.ok()) { if (status.IsNotFound()) return std::nullopt; - LogPrintf("LevelDB read failure: %s\n", status.ToString()); + LogError("LevelDB read failure: %s", status.ToString()); HandleError(status); } return strValue; @@ -324,7 +324,7 @@ bool CDBWrapper::ExistsImpl(std::span key) const if (!status.ok()) { if (status.IsNotFound()) return false; - LogPrintf("LevelDB read failure: %s\n", status.ToString()); + LogError("LevelDB read failure: %s", status.ToString()); HandleError(status); } return true; diff --git a/src/flatfile.cpp b/src/flatfile.cpp index df6596e9405..33d8baf44f9 100644 --- a/src/flatfile.cpp +++ b/src/flatfile.cpp @@ -41,11 +41,11 @@ FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool read_only) const if (!file && !read_only) file = fsbridge::fopen(path, "wb+"); if (!file) { - LogPrintf("Unable to open file %s\n", fs::PathToString(path)); + LogError("Unable to open file %s", fs::PathToString(path)); return nullptr; } if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) { - LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, fs::PathToString(path)); + LogError("Unable to seek to position %u of %s", pos.nPos, fs::PathToString(path)); if (fclose(file) != 0) { LogError("Unable to close file %s", fs::PathToString(path)); } diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 684b85fac1a..c9f8e93f19f 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -462,7 +462,7 @@ bool InitHTTPServer(const util::SignalInterrupt& interrupt) raii_evhttp http_ctr = obtain_evhttp(base_ctr.get()); struct evhttp* http = http_ctr.get(); if (!http) { - LogPrintf("couldn't create evhttp. Exiting.\n"); + LogError("Couldn't create evhttp. Exiting."); return false; } @@ -472,7 +472,7 @@ bool InitHTTPServer(const util::SignalInterrupt& interrupt) evhttp_set_gencb(http, http_request_cb, (void*)&interrupt); if (!HTTPBindAddresses(http)) { - LogPrintf("Unable to bind any endpoint for RPC server\n"); + LogError("Unable to bind any endpoint for RPC server"); return false; } diff --git a/src/node/utxo_snapshot.cpp b/src/node/utxo_snapshot.cpp index ca5491bdc2b..af06d832db9 100644 --- a/src/node/utxo_snapshot.cpp +++ b/src/node/utxo_snapshot.cpp @@ -32,14 +32,14 @@ bool WriteSnapshotBaseBlockhash(Chainstate& snapshot_chainstate) FILE* file{fsbridge::fopen(write_to, "wb")}; AutoFile afile{file}; if (afile.IsNull()) { - LogPrintf("[snapshot] failed to open base blockhash file for writing: %s\n", + LogError("[snapshot] failed to open base blockhash file for writing: %s", fs::PathToString(write_to)); return false; } afile << *snapshot_chainstate.m_from_snapshot_blockhash; if (afile.fclose() != 0) { - LogPrintf("[snapshot] failed to close base blockhash file %s after writing\n", + LogError("[snapshot] failed to close base blockhash file %s after writing", fs::PathToString(write_to)); return false; } diff --git a/src/sync.cpp b/src/sync.cpp index fb60e3cf14c..d33a01dc700 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -90,8 +90,8 @@ LockData& GetLockData() { static void potential_deadlock_detected(const LockPair& mismatch, const LockStack& s1, const LockStack& s2) { - LogPrintf("POTENTIAL DEADLOCK DETECTED\n"); - LogPrintf("Previous lock order was:\n"); + LogError("POTENTIAL DEADLOCK DETECTED"); + LogError("Previous lock order was:"); for (const LockStackItem& i : s1) { std::string prefix{}; if (i.first == mismatch.first) { @@ -100,11 +100,11 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac if (i.first == mismatch.second) { prefix = " (2)"; } - LogPrintf("%s %s\n", prefix, i.second.ToString()); + LogError("%s %s", prefix, i.second.ToString()); } std::string mutex_a, mutex_b; - LogPrintf("Current lock order is:\n"); + LogError("Current lock order is:"); for (const LockStackItem& i : s2) { std::string prefix{}; if (i.first == mismatch.first) { @@ -115,7 +115,7 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac prefix = " (2)"; mutex_b = i.second.Name(); } - LogPrintf("%s %s\n", prefix, i.second.ToString()); + LogError("%s %s", prefix, i.second.ToString()); } if (g_debug_lockorder_abort) { tfm::format(std::cerr, "Assertion failed: detected inconsistent lock order for %s, details in debug log.\n", s2.back().second.ToString()); @@ -126,14 +126,14 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac static void double_lock_detected(const void* mutex, const LockStack& lock_stack) { - LogPrintf("DOUBLE LOCK DETECTED\n"); - LogPrintf("Lock order:\n"); + LogError("DOUBLE LOCK DETECTED"); + LogError("Lock order:"); for (const LockStackItem& i : lock_stack) { std::string prefix{}; if (i.first == mutex) { prefix = " (*)"; } - LogPrintf("%s %s\n", prefix, i.second.ToString()); + LogError("%s %s", prefix, i.second.ToString()); } if (g_debug_lockorder_abort) { tfm::format(std::cerr, @@ -223,10 +223,10 @@ void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, c } } - LogPrintf("INCONSISTENT LOCK ORDER DETECTED\n"); - LogPrintf("Current lock order (least recent first) is:\n"); + LogError("INCONSISTENT LOCK ORDER DETECTED"); + LogError("Current lock order (least recent first) is:"); for (const LockStackItem& i : lock_stack) { - LogPrintf(" %s\n", i.second.ToString()); + LogError(" %s", i.second.ToString()); } if (g_debug_lockorder_abort) { tfm::format(std::cerr, "%s:%s %s was not most recent critical section locked, details in debug log.\n", file, line, guardname); diff --git a/src/txdb.cpp b/src/txdb.cpp index 2a1de5f8497..68cb693902e 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -137,7 +137,7 @@ bool CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashB if (m_options.simulate_crash_ratio) { static FastRandomContext rng; if (rng.randrange(m_options.simulate_crash_ratio) == 0) { - LogPrintf("Simulating a crash. Goodbye.\n"); + LogError("Simulating a crash. Goodbye."); _Exit(0); } } diff --git a/src/util/fs_helpers.cpp b/src/util/fs_helpers.cpp index b5dc1cb3320..b23b2dc29dd 100644 --- a/src/util/fs_helpers.cpp +++ b/src/util/fs_helpers.cpp @@ -102,28 +102,28 @@ std::streampos GetFileSize(const char* path, std::streamsize max) bool FileCommit(FILE* file) { if (fflush(file) != 0) { // harmless if redundantly called - LogPrintf("fflush failed: %s\n", SysErrorString(errno)); + LogError("fflush failed: %s", SysErrorString(errno)); return false; } #ifdef WIN32 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); if (FlushFileBuffers(hFile) == 0) { - LogPrintf("FlushFileBuffers failed: %s\n", Win32ErrorString(GetLastError())); + LogError("FlushFileBuffers failed: %s", Win32ErrorString(GetLastError())); return false; } #elif defined(__APPLE__) && defined(F_FULLFSYNC) if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success - LogPrintf("fcntl F_FULLFSYNC failed: %s\n", SysErrorString(errno)); + LogError("fcntl F_FULLFSYNC failed: %s", SysErrorString(errno)); return false; } #elif HAVE_FDATASYNC if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync - LogPrintf("fdatasync failed: %s\n", SysErrorString(errno)); + LogError("fdatasync failed: %s", SysErrorString(errno)); return false; } #else if (fsync(fileno(file)) != 0 && errno != EINVAL) { - LogPrintf("fsync failed: %s\n", SysErrorString(errno)); + LogError("fsync failed: %s", SysErrorString(errno)); return false; } #endif @@ -235,7 +235,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate) return fs::path(pszPath); } - LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n"); + LogError("SHGetSpecialFolderPathW() failed, could not obtain requested path."); return fs::path(""); } #endif diff --git a/src/validation.cpp b/src/validation.cpp index 8456dbb95bf..42a710b23aa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1196,7 +1196,7 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws) script_verify_flags currentBlockScriptVerifyFlags{GetBlockScriptFlags(*m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman)}; if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags, ws.m_precomputed_txdata, m_active_chainstate.CoinsTip(), GetValidationCache())) { - LogPrintf("BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s\n", hash.ToString(), state.ToString()); + LogError("BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s", hash.ToString(), state.ToString()); return Assume(false); } @@ -3378,8 +3378,8 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< // Belt-and-suspenders check that we aren't attempting to advance the background // chainstate past the snapshot base block. if (WITH_LOCK(::cs_main, return m_disabled)) { - LogPrintf("m_disabled is set - this chainstate should not be in operation. " - "Please report this as a bug. %s\n", CLIENT_BUGREPORT); + LogError("m_disabled is set - this chainstate should not be in operation. " + "Please report this as a bug. %s", CLIENT_BUGREPORT); return false; } @@ -4702,12 +4702,12 @@ VerifyDBResult CVerifyDB::VerifyDB( CBlock block; // check level 0: read from disk if (!chainstate.m_blockman.ReadBlock(block, *pindex)) { - LogPrintf("Verification error: ReadBlock failed at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); + LogError("Verification error: ReadBlock failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } // check level 1: verify block validity if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params)) { - LogPrintf("Verification error: found bad block at %d, hash=%s (%s)\n", + LogError("Verification error: found bad block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } @@ -4716,7 +4716,7 @@ VerifyDBResult CVerifyDB::VerifyDB( CBlockUndo undo; if (!pindex->GetUndoPos().IsNull()) { if (!chainstate.m_blockman.ReadBlockUndo(undo, *pindex)) { - LogPrintf("Verification error: found bad undo data at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); + LogError("Verification error: found bad undo data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } } @@ -4729,7 +4729,7 @@ VerifyDBResult CVerifyDB::VerifyDB( assert(coins.GetBestBlock() == pindex->GetBlockHash()); DisconnectResult res = chainstate.DisconnectBlock(block, pindex, coins); if (res == DISCONNECT_FAILED) { - LogPrintf("Verification error: irrecoverable inconsistency in block data at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); + LogError("Verification error: irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } if (res == DISCONNECT_UNCLEAN) { @@ -4745,7 +4745,7 @@ VerifyDBResult CVerifyDB::VerifyDB( if (chainstate.m_chainman.m_interrupt) return VerifyDBResult::INTERRUPTED; } if (pindexFailure) { - LogPrintf("Verification error: coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainstate.m_chain.Height() - pindexFailure->nHeight + 1, nGoodTransactions); + LogError("Verification error: coin database inconsistencies found (last %i blocks, %i good transactions before that)", chainstate.m_chain.Height() - pindexFailure->nHeight + 1, nGoodTransactions); return VerifyDBResult::CORRUPTED_BLOCK_DB; } if (skipped_l3_checks) { @@ -4768,11 +4768,11 @@ VerifyDBResult CVerifyDB::VerifyDB( pindex = chainstate.m_chain.Next(pindex); CBlock block; if (!chainstate.m_blockman.ReadBlock(block, *pindex)) { - LogPrintf("Verification error: ReadBlock failed at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); + LogError("Verification error: ReadBlock failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } if (!chainstate.ConnectBlock(block, state, pindex, coins)) { - LogPrintf("Verification error: found unconnectable block at %d, hash=%s (%s)\n", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); + LogError("Verification error: found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); return VerifyDBResult::CORRUPTED_BLOCK_DB; } if (chainstate.m_chainman.m_interrupt) return VerifyDBResult::INTERRUPTED; @@ -5635,7 +5635,7 @@ Chainstate& ChainstateManager::InitializeChainstate(CTxMemPool* mempool) const bool destroyed = DestroyDB(path_str); if (!destroyed) { - LogPrintf("error: leveldb DestroyDB call failed on %s\n", path_str); + LogError("leveldb DestroyDB call failed on %s", path_str); } // Datadir should be removed from filesystem; otherwise initialization may detect @@ -6334,8 +6334,8 @@ util::Result Chainstate::InvalidateCoinsDBOnDisk() auto src_str = fs::PathToString(snapshot_datadir); auto dest_str = fs::PathToString(invalid_path); - LogPrintf("%s: error renaming file '%s' -> '%s': %s\n", - __func__, src_str, dest_str, e.what()); + LogError("While invalidating the coins db: Error renaming file '%s' -> '%s': %s", + src_str, dest_str, e.what()); return util::Error{strprintf(_( "Rename of '%s' -> '%s' failed. " "You should resolve this by manually moving or deleting the invalid " @@ -6354,7 +6354,7 @@ bool ChainstateManager::DeleteSnapshotChainstate() fs::path snapshot_datadir = Assert(node::FindSnapshotChainstateDir(m_options.datadir)).value(); if (!DeleteCoinsDBFromDisk(snapshot_datadir, /*is_snapshot=*/ true)) { - LogPrintf("Deletion of %s failed. Please remove it manually to continue reindexing.\n", + LogError("Deletion of %s failed. Please remove it manually to continue reindexing.", fs::PathToString(snapshot_datadir)); return false; } @@ -6416,8 +6416,8 @@ bool ChainstateManager::ValidatedSnapshotCleanup() // is in-memory, in which case we can't do on-disk cleanup. You'd better be // in a unittest! if (!ibd_chainstate_path_maybe || !snapshot_chainstate_path_maybe) { - LogPrintf("[snapshot] snapshot chainstate cleanup cannot happen with " - "in-memory chainstates. You are testing, right?\n"); + LogError("[snapshot] snapshot chainstate cleanup cannot happen with " + "in-memory chainstates. You are testing, right?"); return false; } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 276817146c6..dad21eaf50f 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -755,7 +755,7 @@ std::optional LegacyDataSPKM::MigrateToDescriptor() // Make sure that we have accounted for all scriptPubKeys if (!Assume(spks.empty())) { - LogPrintf("%s\n", STR_INTERNAL_BUG("Error: Some output scripts were not migrated.\n")); + LogError("%s", STR_INTERNAL_BUG("Error: Some output scripts were not migrated.")); return std::nullopt; }