diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index ff5eb86a6..b032ac865 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -790,12 +790,10 @@ bool Ledger::walkLedger (beast::Journal j) const stateMap_->walkMap (missingNodes1, 32); } - if (ShouldLog (lsINFO, Ledger) && !missingNodes1.empty ()) + if (j.info && !missingNodes1.empty ()) { - JLOG (j.info) - << missingNodes1.size () << " missing account node(s)"; - JLOG (j.info) - << "First: " << missingNodes1[0]; + j.info << missingNodes1.size () << " missing account node(s)"; + j.info << "First: " << missingNodes1[0]; } if (txMap_->getHash().isZero() && @@ -809,12 +807,10 @@ bool Ledger::walkLedger (beast::Journal j) const txMap_->walkMap (missingNodes2, 32); } - if (ShouldLog (lsINFO, Ledger) && !missingNodes2.empty ()) + if (j.info && !missingNodes2.empty ()) { - JLOG (j.info) - << missingNodes2.size () << " missing transaction node(s)"; - JLOG (j.info) - << "First: " << missingNodes2[0]; + j.info << missingNodes2.size () << " missing transaction node(s)"; + j.info << "First: " << missingNodes2[0]; } return missingNodes1.empty () && missingNodes2.empty (); @@ -1057,16 +1053,15 @@ static bool saveValidatedLedger ( sql += ")"; } sql += ";"; - if (ShouldLog (lsTRACE, Ledger)) - { - JLOG (j.trace) << "ActTx: " << sql; - } + JLOG (j.trace) << "ActTx: " << sql; *db << sql; } else + { JLOG (j.warning) << "Transaction in ledger " << seq << " affects no accounts"; + } *db << (STTx::getMetaSQLInsertReplaceHeader () + diff --git a/src/ripple/app/ledger/OrderBookDB.cpp b/src/ripple/app/ledger/OrderBookDB.cpp index a54b7be24..d1762dd66 100644 --- a/src/ripple/app/ledger/OrderBookDB.cpp +++ b/src/ripple/app/ledger/OrderBookDB.cpp @@ -130,7 +130,7 @@ void OrderBookDB::update( } catch (const SHAMapMissingNode&) { - JLOG (j_.info) + JLOG (j_.info) << "OrderBookDB::update encountered a missing node"; std::lock_guard sl (mLock); mSeq = 0; diff --git a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp index 0de15b6c1..9ddbcd984 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp @@ -367,15 +367,17 @@ void LedgerConsensusImp::mapCompleteInternal ( std::shared_ptr const& map, bool acquired) { - CondLog (acquired, lsDEBUG, LedgerConsensus) - << "We have acquired TXS " << hash; + if (acquired) + { + JLOG (j_.trace) << "We have acquired txs " << hash; + } if (!map) // If the map was invalid { - // this is an invalid/corrupt map - mAcquired[hash] = map; JLOG (j_.warning) - << "A trusted node directed us to acquire an invalid TXN map"; + << "Tried to acquire invalid transaction map: " + << hash; + mAcquired[hash] = map; return; } @@ -387,9 +389,7 @@ void LedgerConsensusImp::mapCompleteInternal ( if (it != mAcquired.end ()) { if (it->second) - { return; // we already have this map - } // We previously failed to acquire this map, now we have it mAcquired.erase (hash); @@ -422,14 +422,20 @@ void LedgerConsensusImp::mapCompleteInternal ( createDisputes (it2->second, map); } else if (!mOurPosition) + { JLOG (j_.debug) << "Not creating disputes: no position yet."; + } else if (mOurPosition->isBowOut ()) + { JLOG (j_.warning) << "Not creating disputes: not participating."; + } else + { JLOG (j_.debug) << "Not creating disputes: identical position."; + } mAcquired[hash] = map; @@ -446,11 +452,11 @@ void LedgerConsensusImp::mapCompleteInternal ( { adjustCount (map, peers); } - else + else if (acquired) { - CondLog (acquired, lsWARNING, LedgerConsensus) - << "By the time we got the map " - << hash << " no peers were proposing it"; + JLOG (j_.warning) + << "By the time we got the map " << hash + << " no peers were proposing it"; } } @@ -1623,10 +1629,14 @@ void LedgerConsensusImp::updateOurPositions () } } - CondLog (!mHaveCloseTimeConsensus, lsDEBUG, LedgerConsensus) - << "No CT consensus: Proposers:" << mPeerPositions.size () - << " Proposing:" << (mProposing ? "yes" : "no") << " Thresh:" - << threshConsensus << " Pos:" << closeTime.time_since_epoch().count(); + if (!mHaveCloseTimeConsensus) + { + JLOG (j_.debug) << "No CT consensus:" + << " Proposers:" << mPeerPositions.size () + << " Proposing:" << (mProposing ? "yes" : "no") + << " Thresh:" << threshConsensus + << " Pos:" << closeTime.time_since_epoch().count(); + } } // Temporarily send a new proposal if there's any change to our diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 44eb815b7..cc7b9a4ff 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -596,9 +596,14 @@ LedgerMaster::fixMismatch (Ledger::ref ledger) if (otherLedger && (otherLedger->getHash () == *hash)) { // we closed the seam - CondLog (invalidate != 0, lsWARNING, LedgerMaster) << - "Match at " << lSeq << ", " << invalidate << - " prior ledgers invalidated"; + if (invalidate != 0) + { + JLOG (m_journal.warning) + << "Match at " << lSeq + << ", " << invalidate + << " prior ledgers invalidated"; + } + return; } } @@ -609,8 +614,11 @@ LedgerMaster::fixMismatch (Ledger::ref ledger) } // all prior ledgers invalidated - CondLog (invalidate != 0, lsWARNING, LedgerMaster) << "All " << - invalidate << " prior ledgers invalidated"; + if (invalidate != 0) + { + JLOG (m_journal.warning) << + "All " << invalidate << " prior ledgers invalidated"; + } } void diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 387be6fad..a95e5edb4 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -100,6 +100,22 @@ private: std::uint32_t maxSeq = 0; std::mutex maxSeqLock; + void acquire ( + uint256 const& hash, + std::uint32_t seq) + { + if (hash.isNonZero()) + { + auto j = app_.journal ("Ledger"); + + JLOG (j.error) << + "Missing node in " << to_string (hash); + + app_.getInboundLedgers ().acquire ( + hash, seq, InboundLedger::fcGENERIC); + } + } + public: AppFamily (AppFamily const&) = delete; AppFamily& operator= (AppFamily const&) = delete; @@ -162,7 +178,10 @@ public: void missing_node (std::uint32_t seq) override { - WriteLog (lsERROR, Ledger) << "Missing node in " << seq; + auto j = app_.journal ("Ledger"); + + JLOG (j.error) << + "Missing node in " << seq; // prevent recursive invocation std::unique_lock lock (maxSeqLock); @@ -179,11 +198,9 @@ public: lock.unlock(); // This can invoke the missing node handler - uint256 hash = app_.getLedgerMaster().getHashBySeq (seq); - - if (hash.isNonZero()) - app_.getInboundLedgers().acquire ( - hash, seq, InboundLedger::fcGENERIC); + acquire ( + app_.getLedgerMaster().getHashBySeq (seq), + seq); lock.lock(); } @@ -191,7 +208,8 @@ public: } else if (maxSeq < seq) { - // We found a more recent ledger with a missing node + // We found a more recent ledger with a + // missing node maxSeq = seq; } } @@ -199,14 +217,7 @@ public: void missing_node (uint256 const& hash) override { - if (hash.isNonZero()) - { - WriteLog (lsERROR, Ledger) << "Missing node in " - << to_string (hash); - - app_.getInboundLedgers ().acquire ( - hash, 0, InboundLedger::fcGENERIC); - } + acquire (hash, 0); } }; diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index a407f0098..a1bc9c18c 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -225,6 +225,7 @@ int run (int argc, char** argv) ("ledgerfile", po::value (), "Load the specified ledger file.") ("start", "Start from a fresh Ledger.") ("net", "Get the initial ledger from the network.") + ("debug", "Enable normally suppressed debug logging") ("fg", "Run in the foreground.") ("import", importText.c_str ()) ("version", "Display the build version.") @@ -421,8 +422,6 @@ int run (int argc, char** argv) if (!vm.count ("parameters")) { auto logs = std::make_unique(); - auto timeKeeper = make_TimeKeeper( - logs->journal("TimeKeeper")); if (vm.count ("quiet")) logs->severity (beast::Journal::kFatal); @@ -431,6 +430,12 @@ int run (int argc, char** argv) else logs->severity (beast::Journal::kInfo); + if (vm.count ("debug")) + setDebugJournalSink (logs->get("Debug")); + + auto timeKeeper = make_TimeKeeper( + logs->journal("TimeKeeper")); + auto app = make_Application( std::move(config), std::move(logs), diff --git a/src/ripple/app/paths/PathState.cpp b/src/ripple/app/paths/PathState.cpp index e53052863..bef4ee6e2 100644 --- a/src/ripple/app/paths/PathState.cpp +++ b/src/ripple/app/paths/PathState.cpp @@ -53,19 +53,24 @@ void PathState::reset(STAmount const& in, STAmount const& out) saInAct = in; saOutAct = out; - CondLog (inReq() > zero && inAct() >= inReq(), - lsWARNING, RippleCalc) - << "rippleCalc: DONE:" - << " inAct()=" << inAct() - << " inReq()=" << inReq(); + if (inReq() > zero && inAct() >= inReq()) + { + JLOG (j_.warning) + << "rippleCalc: DONE:" + << " inAct()=" << inAct() + << " inReq()=" << inReq(); + } assert (inReq() < zero || inAct() < inReq()); // Error if done. - CondLog (outAct() >= outReq(), lsWARNING, RippleCalc) - << "rippleCalc: ALREADY DONE:" - << " saOutAct=" << outAct() - << " saOutReq=" << outReq(); + if (outAct() >= outReq()) + { + JLOG (j_.warning) + << "rippleCalc: ALREADY DONE:" + << " saOutAct=" << outAct() + << " saOutReq=" << outReq(); + } assert(outAct() < outReq()); assert (nodes().size () >= 2); diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index 81bde1609..e1169128a 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -831,9 +831,13 @@ STPathSet& Pathfinder::addPathsForType (PathType const& pathType) break; } - CondLog (mCompletePaths.size () != initialSize, lsDEBUG, Pathfinder) - << (mCompletePaths.size () - initialSize) - << " complete paths added"; + if (mCompletePaths.size () != initialSize) + { + JLOG (j_.debug) + << (mCompletePaths.size () - initialSize) + << " complete paths added"; + } + JLOG (j_.debug) << "getPaths> " << pathsOut.size () << " partial paths found"; return pathsOut; diff --git a/src/ripple/app/paths/RippleCalc.cpp b/src/ripple/app/paths/RippleCalc.cpp index a74527891..3a8a5c64e 100644 --- a/src/ripple/app/paths/RippleCalc.cpp +++ b/src/ripple/app/paths/RippleCalc.cpp @@ -248,7 +248,7 @@ TER RippleCalc::rippleCalculate () // This should never happen. Consider the path dry JLOG (j_.warning) - << "rippelCalc: Non-dry path moves no funds"; + << "rippleCalc: Non-dry path moves no funds"; assert (false); @@ -257,13 +257,15 @@ TER RippleCalc::rippleCalculate () } else { - CondLog (!pathState->inPass() || !pathState->outPass(), - lsDEBUG, RippleCalc) - << "rippleCalc: better:" - << " uQuality=" - << amountFromRate (pathState->quality()) - << " inPass()=" << pathState->inPass() - << " saOutPass=" << pathState->outPass(); + if (!pathState->inPass() || !pathState->outPass()) + { + JLOG (j_.debug) + << "rippleCalc: better:" + << " uQuality=" + << amountFromRate (pathState->quality()) + << " inPass()=" << pathState->inPass() + << " saOutPass=" << pathState->outPass(); + } assert (pathState->inPass() && pathState->outPass()); @@ -293,16 +295,17 @@ TER RippleCalc::rippleCalculate () } ++iPass; - if (ShouldLog (lsDEBUG, RippleCalc)) + + if (j_.debug) { - JLOG (j_.debug) + j_.debug << "rippleCalc: Summary:" << " Pass: " << iPass << " Dry: " << iDry << " Paths: " << pathStateList_.size (); for (auto pathState: pathStateList_) { - JLOG (j_.debug) + j_.debug << "rippleCalc: " << "Summary: " << pathState->index() << " rate: " diff --git a/src/ripple/app/paths/cursor/DeliverNodeForward.cpp b/src/ripple/app/paths/cursor/DeliverNodeForward.cpp index 4e9a629dc..90f35a2bd 100644 --- a/src/ripple/app/paths/cursor/DeliverNodeForward.cpp +++ b/src/ripple/app/paths/cursor/DeliverNodeForward.cpp @@ -338,10 +338,13 @@ TER PathCursor::deliverNodeForward ( } else { - CondLog (saOutPassAct >= saOutFunded, lsWARNING, RippleCalc) - << "deliverNodeForward: TOO MUCH:" - << " saOutPassAct=" << saOutPassAct - << " saOutFunded=" << saOutFunded; + if (saOutPassAct >= saOutFunded) + { + JLOG (j_.warning) + << "deliverNodeForward: TOO MUCH:" + << " saOutPassAct=" << saOutPassAct + << " saOutFunded=" << saOutFunded; + } assert (saOutPassAct < saOutFunded); } diff --git a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp index d20ceba49..160a9b94a 100644 --- a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp +++ b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp @@ -337,10 +337,13 @@ TER PathCursor::deliverNodeReverseImpl ( previousNode().saRevDeliver += saInPassAct; } - CondLog (saOutAct > saOutReq, lsWARNING, RippleCalc) - << "deliverNodeReverse: TOO MUCH:" - << " saOutAct=" << saOutAct - << " saOutReq=" << saOutReq; + if (saOutAct > saOutReq) + { + JLOG (j_.warning) + << "deliverNodeReverse: TOO MUCH:" + << " saOutAct=" << saOutAct + << " saOutReq=" << saOutReq; + } assert(saOutAct <= saOutReq); diff --git a/src/ripple/app/paths/cursor/NextIncrement.cpp b/src/ripple/app/paths/cursor/NextIncrement.cpp index 7d555bc31..efab4a259 100644 --- a/src/ripple/app/paths/cursor/NextIncrement.cpp +++ b/src/ripple/app/paths/cursor/NextIncrement.cpp @@ -39,31 +39,23 @@ void PathCursor::nextIncrement () const { // The next state is what is available in preference order. // This is calculated when referenced accounts changed. - // VFALCO-FIXME this generates errors - // JLOG (j_.trace) - // << "nextIncrement: Path In: " << pathState_.getJson (); auto status = liquidity(); if (status == tesSUCCESS) { - auto isDry = pathState_.isDry(); - CondLog (isDry, lsDEBUG, RippleCalc) - << "nextIncrement: Error forwardLiquidity reported success" - << " on dry path:" - << " saOutPass=" << pathState_.outPass() - << " inPass()=" << pathState_.inPass(); - - if (isDry) + if (pathState_.isDry()) + { + JLOG (j_.debug) + << "nextIncrement: success on dry path:" + << " outPass=" << pathState_.outPass() + << " inPass=" << pathState_.inPass(); Throw ("Made no progress."); + } // Calculate relative quality. pathState_.setQuality(getRate ( pathState_.outPass(), pathState_.inPass())); - - // VFALCO-FIXME this generates errors - // JLOG (j_.trace) - // << "nextIncrement: Path after forward: " << pathState_.getJson (); } else { diff --git a/src/ripple/basics/Log.h b/src/ripple/basics/Log.h index 4e5dca241..0548cbd8c 100644 --- a/src/ripple/basics/Log.h +++ b/src/ripple/basics/Log.h @@ -236,6 +236,22 @@ private: #define JLOG(x) if (!x) { } else x #endif +//------------------------------------------------------------------------------ +// Debug logging: + +/** Returns the debug journal. The journal may drain to a null sink. */ +beast::Journal const& +debugJournal(); + +/** Set the sink for the debug journal + + This operation is not thread safe and should only be called + from a controlled context, when no other threads are in a + call to debugJournal. +*/ +void +setDebugJournalSink(beast::Journal::Sink& sink); + //------------------------------------------------------------------------------ // VFALCO DEPRECATED Temporary transition function until interfaces injected inline @@ -265,25 +281,6 @@ private: beast::Journal::Severity const severity_; }; -// VFALCO DEPRECATED Inject beast::Journal instead -#define ShouldLog(s, k) \ - ::ripple::deprecatedLogs()[#k].active(::ripple::Logs::toSeverity (s)) - -// DEPRECATED -#define WriteLog(s, k) \ - if (!ShouldLog(s, k)) \ - do {} while (0); \ - else \ - ::beast::Journal::Stream (::ripple::deprecatedLogs()[#k], \ - ::ripple::Logs::toSeverity(s)) -// DEPRECATED -#define CondLog(c, s, k) \ - if (!ShouldLog(s, k) || !(c)) \ - do {} while(0); \ - else \ - ::beast::Journal::Stream (::ripple::deprecatedLogs()[#k], \ - ::ripple::Logs::toSeverity(s)) - } // ripple #endif diff --git a/src/ripple/basics/impl/Log.cpp b/src/ripple/basics/impl/Log.cpp index 0eeec1bd1..426580bfd 100644 --- a/src/ripple/basics/impl/Log.cpp +++ b/src/ripple/basics/impl/Log.cpp @@ -329,4 +329,22 @@ Logs::format (std::string& output, std::string const& message, } } +//------------------------------------------------------------------------------ +static std::unique_ptr debugJournal_; + +beast::Journal const& +debugJournal() +{ + if (!debugJournal_) + debugJournal_ = std::make_unique(); + + return *debugJournal_; +} + +void +setDebugJournalSink(beast::Journal::Sink& sink) +{ + debugJournal_ = std::make_unique(sink); +} + } // ripple diff --git a/src/ripple/core/SociDB.h b/src/ripple/core/SociDB.h index 5d6c565aa..05313dbbf 100644 --- a/src/ripple/core/SociDB.h +++ b/src/ripple/core/SociDB.h @@ -52,10 +52,12 @@ T rangeCheckedCast (C c) std::numeric_limits::is_signed && c < std::numeric_limits::lowest ())) { - WriteLog (lsERROR, RangeCheckedCast) - << "Range error. Min: " << std::numeric_limits::lowest () - << " Max: " << std::numeric_limits::max () << " Got: " << c; + JLOG (debugJournal().error) << "rangeCheckedCast domain error:" + << " value = " << c + << " min = " << std::numeric_limits::lowest () + << " max: " << std::numeric_limits::max (); } + return static_cast(c); } diff --git a/src/ripple/ledger/impl/View.cpp b/src/ripple/ledger/impl/View.cpp index c244585ae..7a6c136cc 100644 --- a/src/ripple/ledger/impl/View.cpp +++ b/src/ripple/ledger/impl/View.cpp @@ -1435,7 +1435,7 @@ accountSend (ApplyView& view, ? view.peek (keylet::account(uReceiverID)) : SLE::pointer (); - if (ShouldLog (lsTRACE, View)) + if (j.trace) { std::string sender_bal ("-"); std::string receiver_bal ("-"); @@ -1446,7 +1446,7 @@ accountSend (ApplyView& view, if (receiver) receiver_bal = receiver->getFieldAmount (sfBalance).getFullText (); - JLOG (j.trace) << "accountSend> " << + j.trace << "accountSend> " << to_string (uSenderID) << " (" << sender_bal << ") -> " << to_string (uReceiverID) << " (" << receiver_bal << ") : " << saAmount.getFullText (); @@ -1479,7 +1479,7 @@ accountSend (ApplyView& view, view.update (receiver); } - if (ShouldLog (lsTRACE, View)) + if (j.trace) { std::string sender_bal ("-"); std::string receiver_bal ("-"); @@ -1490,7 +1490,7 @@ accountSend (ApplyView& view, if (receiver) receiver_bal = receiver->getFieldAmount (sfBalance).getFullText (); - JLOG (j.trace) << "accountSend< " << + j.trace << "accountSend< " << to_string (uSenderID) << " (" << sender_bal << ") -> " << to_string (uReceiverID) << " (" << receiver_bal << ") : " << saAmount.getFullText (); diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 215349005..a25b73576 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -893,10 +893,10 @@ public: // <-- { method: xyz, params: [... ] } or { error: ..., ... } Json::Value parseCommand (std::string strMethod, Json::Value jvParams, bool allowAnyCommand) { - if (ShouldLog (lsTRACE, RPCParser)) + if (j_.trace) { - JLOG (j_.trace) << "RPC method:" << strMethod; - JLOG (j_.trace) << "RPC params:" << jvParams; + j_.trace << "Method: '" << strMethod << "'"; + j_.trace << "Params: " << jvParams; } struct Command diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index b8a776167..c8d18943f 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -151,7 +151,6 @@ public: bool getVL (Blob& objectVL, int offset, int& length) const; bool getVLLength (int& length, int offset) const; - bool getFieldID (int& type, int& name, int offset) const; int addFieldID (int type, int name); int addFieldID (SerializedTypeID type, int name) { diff --git a/src/ripple/protocol/impl/STAmount.cpp b/src/ripple/protocol/impl/STAmount.cpp index 70cabcabc..8b7293d69 100644 --- a/src/ripple/protocol/impl/STAmount.cpp +++ b/src/ripple/protocol/impl/STAmount.cpp @@ -812,12 +812,6 @@ amountFromJson (SField const& name, Json::Value const& v) if (v.isObject ()) { - WriteLog (lsTRACE, STAmount) << - "value='" << v[jss::value].asString () << - "', currency='" << v["currency"].asString () << - "', issuer='" << v["issuer"].asString () << - "')"; - value = v[jss::value]; currency = v[jss::currency]; issuer = v[jss::issuer]; @@ -916,7 +910,7 @@ amountFromJsonNoThrow (STAmount& result, Json::Value const& jvSource) } catch (const std::exception& e) { - WriteLog (lsDEBUG, STAmount) << + JLOG (debugJournal().debug) << "amountFromJsonNoThrow: caught: " << e.what (); } return false; @@ -1104,9 +1098,6 @@ canonicalizeRound (bool native, std::uint64_t& value, int& offset, bool roundUp) if (!roundUp) // canonicalize already rounds down return; - WriteLog (lsTRACE, STAmount) - << "canonicalizeRound< " << value << ":" << offset; - if (native) { if (offset < 0) @@ -1137,9 +1128,6 @@ canonicalizeRound (bool native, std::uint64_t& value, int& offset, bool roundUp) value /= 10; ++offset; } - - WriteLog (lsTRACE, STAmount) - << "canonicalizeRound> " << value << ":" << offset; } STAmount diff --git a/src/ripple/protocol/impl/STArray.cpp b/src/ripple/protocol/impl/STArray.cpp index 76f664206..db5360ac4 100644 --- a/src/ripple/protocol/impl/STArray.cpp +++ b/src/ripple/protocol/impl/STArray.cpp @@ -76,7 +76,7 @@ STArray::STArray (SerialIter& sit, SField const& f) if ((type == STI_OBJECT) && (field == 1)) { - WriteLog (lsWARNING, STObject) << + JLOG (debugJournal().warning) << "Encountered array with end of object marker"; Throw ("Illegal terminator in array"); } @@ -85,14 +85,15 @@ STArray::STArray (SerialIter& sit, SField const& f) if (fn.isInvalid ()) { - WriteLog (lsTRACE, STObject) << + JLOG (debugJournal().trace) << "Unknown field: " << type << "/" << field; Throw ("Unknown field"); } if (fn.fieldType != STI_OBJECT) { - WriteLog (lsTRACE, STObject) << "Array contains non-object"; + JLOG (debugJournal().trace) << + "Array contains non-object"; Throw ("Non-object in array"); } @@ -172,16 +173,8 @@ void STArray::add (Serializer& s) const bool STArray::isEquivalent (const STBase& t) const { - const STArray* v = dynamic_cast (&t); - - if (!v) - { - WriteLog (lsDEBUG, STObject) << - "notEquiv " << getFullText() << " not array"; - return false; - } - - return v_ == v->v_; + auto v = dynamic_cast (&t); + return v != nullptr && v_ == v->v_; } void STArray::sort (bool (*compare) (const STObject&, const STObject&)) diff --git a/src/ripple/protocol/impl/STInteger.cpp b/src/ripple/protocol/impl/STInteger.cpp index 3cebb66d4..49149817b 100644 --- a/src/ripple/protocol/impl/STInteger.cpp +++ b/src/ripple/protocol/impl/STInteger.cpp @@ -51,6 +51,9 @@ STUInt8::getText () const if (transResultInfo (static_cast (value_), token, human)) return human; + + JLOG (debugJournal().warning) + << "Unknown result code in metadata: " << value_; } return beast::lexicalCastThrow (value_); @@ -66,9 +69,9 @@ STUInt8::getJson (int) const if (transResultInfo (static_cast (value_), token, human)) return token; - else - WriteLog (lsWARNING, STBase) - << "Unknown result code in metadata: " << value_; + + JLOG (debugJournal().warning) + << "Unknown result code in metadata: " << value_; } return value_; diff --git a/src/ripple/protocol/impl/STLedgerEntry.cpp b/src/ripple/protocol/impl/STLedgerEntry.cpp index c49d0f2ff..054cf35e1 100644 --- a/src/ripple/protocol/impl/STLedgerEntry.cpp +++ b/src/ripple/protocol/impl/STLedgerEntry.cpp @@ -78,9 +78,12 @@ void STLedgerEntry::setSLEType () type_ = mFormat->getType (); if (!setType (mFormat->elements)) { - WriteLog (lsWARNING, SerializedLedger) - << "Ledger entry not valid for type " << mFormat->getName (); - WriteLog (lsWARNING, SerializedLedger) << getJson (0); + if (auto j = debugJournal().warning) + { + j << "Ledger entry not valid for type " << mFormat->getName (); + j << "Object: " << getJson (0); + } + Throw ("ledger entry not valid for type"); } } @@ -137,7 +140,9 @@ bool STLedgerEntry::thread (uint256 const& txID, std::uint32_t ledgerSeq, uint256& prevTxID, std::uint32_t& prevLedgerID) { uint256 oldPrevTxID = getFieldH256 (sfPreviousTxnID); - WriteLog (lsTRACE, SerializedLedger) << "Thread Tx:" << txID << " prev:" << oldPrevTxID; + + JLOG (debugJournal().trace) + << "Thread Tx:" << txID << " prev:" << oldPrevTxID; if (oldPrevTxID == txID) { diff --git a/src/ripple/protocol/impl/STObject.cpp b/src/ripple/protocol/impl/STObject.cpp index b2e765529..43b0db65e 100644 --- a/src/ripple/protocol/impl/STObject.cpp +++ b/src/ripple/protocol/impl/STObject.cpp @@ -113,9 +113,9 @@ bool STObject::setType (const SOTemplate& type) { if ((e->flags == SOE_DEFAULT) && iter->get().isDefault()) { - WriteLog (lsWARNING, STObject) << - "setType( " << getFName ().getName () << - " ) invalid default " << e->e_field.fieldName; + JLOG (debugJournal().warning) + << "setType(" << getFName().getName() + << "): explicit default " << e->e_field.fieldName; valid = false; } v.emplace_back(std::move(*iter)); @@ -125,9 +125,9 @@ bool STObject::setType (const SOTemplate& type) { if (e->flags == SOE_REQUIRED) { - WriteLog (lsWARNING, STObject) << - "setType( " << getFName ().getName () << - " ) invalid missing " << e->e_field.fieldName; + JLOG (debugJournal().warning) + << "setType(" << getFName().getName() + << "): missing " << e->e_field.fieldName; valid = false; } v.emplace_back(detail::nonPresentObject, e->e_field); @@ -138,9 +138,9 @@ bool STObject::setType (const SOTemplate& type) // Anything left over in the object must be discardable if (! e->getFName().isDiscardable()) { - WriteLog (lsWARNING, STObject) << - "setType( " << getFName ().getName () << - " ) invalid leftover " << e->getFName ().getName (); + JLOG (debugJournal().warning) + << "setType(" << getFName().getName() + << "): non-discardable leftover " << e->getFName().getName (); valid = false; } } @@ -208,8 +208,8 @@ bool STObject::set (SerialIter& sit, int depth) if ((type == STI_ARRAY) && (field == 1)) { - WriteLog (lsWARNING, STObject) << - "Encountered object with end of array marker"; + JLOG (debugJournal().warning) + << "Encountered object with end of array marker"; Throw ("Illegal terminator in object"); } @@ -221,9 +221,9 @@ bool STObject::set (SerialIter& sit, int depth) if (fn.isInvalid ()) { - WriteLog (lsWARNING, STObject) << - "Unknown field: field_type=" << type << - ", field_name=" << field; + JLOG (debugJournal().warning) + << "Unknown field: field_type=" << type + << ", field_name=" << field; Throw ("Unknown field"); } @@ -304,11 +304,7 @@ bool STObject::isEquivalent (const STBase& t) const const STObject* v = dynamic_cast (&t); if (!v) - { - WriteLog (lsDEBUG, STObject) << - "notEquiv " << getFullText() << " not object"; return false; - } if (mType != nullptr && (v->mType == mType)) return equivalentSTObjectSameTemplate (*this, *v); @@ -727,12 +723,7 @@ bool STObject::operator== (const STObject& obj) const } if (!match) - { - WriteLog (lsTRACE, STObject) << - "STObject::operator==: no match for " << - t1->getFName ().getName (); return false; - } } } @@ -744,11 +735,7 @@ bool STObject::operator== (const STObject& obj) const } if (fields != matches) - { - WriteLog (lsTRACE, STObject) << "STObject::operator==: " << - fields << " fields, " << matches << " matches"; return false; - } return true; } diff --git a/src/ripple/protocol/impl/STPathSet.cpp b/src/ripple/protocol/impl/STPathSet.cpp index a8fec73de..27f848f00 100644 --- a/src/ripple/protocol/impl/STPathSet.cpp +++ b/src/ripple/protocol/impl/STPathSet.cpp @@ -64,8 +64,8 @@ STPathSet::STPathSet (SerialIter& sit, SField const& name) { if (path.empty ()) { - WriteLog (lsINFO, STBase) - << "STPathSet: Empty path."; + JLOG (debugJournal().info) + << "Empty path in pathset"; Throw ("empty path"); } @@ -77,9 +77,8 @@ STPathSet::STPathSet (SerialIter& sit, SField const& name) } else if (iType & ~STPathElement::typeAll) { - WriteLog (lsINFO, STBase) - << "STPathSet: Bad path element: " << iType; - + JLOG (debugJournal().info) + << "Bad path element " << iType << " in pathset"; Throw ("bad path element"); } else diff --git a/src/ripple/protocol/impl/STValidation.cpp b/src/ripple/protocol/impl/STValidation.cpp index f6bf76da9..aac14c129 100644 --- a/src/ripple/protocol/impl/STValidation.cpp +++ b/src/ripple/protocol/impl/STValidation.cpp @@ -35,7 +35,8 @@ STValidation::STValidation (SerialIter& sit, bool checkSignature) if (checkSignature && !isValid ()) { - WriteLog (lsTRACE, Ledger) << "Invalid validation " << getJson (0); + JLOG (debugJournal().trace) + << "Invalid validation" << getJson (0); Throw ("Invalid validation"); } } @@ -112,7 +113,8 @@ bool STValidation::isValid (uint256 const& signingHash) const } catch (std::exception const&) { - WriteLog (lsINFO, Ledger) << "exception validating validation"; + JLOG (debugJournal().info) + << "Exception validating validation"; return false; } } diff --git a/src/ripple/protocol/impl/Serializer.cpp b/src/ripple/protocol/impl/Serializer.cpp index b2ca88f4c..3e56f992c 100644 --- a/src/ripple/protocol/impl/Serializer.cpp +++ b/src/ripple/protocol/impl/Serializer.cpp @@ -148,46 +148,6 @@ int Serializer::addFieldID (int type, int name) return ret; } -bool Serializer::getFieldID (int& type, int& name, int offset) const -{ - if (!get8 (type, offset)) - { - WriteLog (lsWARNING, Serializer) << "gFID: unable to get type"; - return false; - } - - name = type & 15; - type >>= 4; - - if (type == 0) - { - // uncommon type - if (!get8 (type, ++offset)) - return false; - - if ((type == 0) || (type < 16)) - { - WriteLog (lsWARNING, Serializer) << "gFID: uncommon type out of range " << type; - return false; - } - } - - if (name == 0) - { - // uncommon name - if (!get8 (name, ++offset)) - return false; - - if ((name == 0) || (name < 16)) - { - WriteLog (lsWARNING, Serializer) << "gFID: uncommon name out of range " << name; - return false; - } - } - - return true; -} - int Serializer::add8 (unsigned char byte) { int ret = mData.size (); diff --git a/src/ripple/websocket/LogWebsockets.cpp b/src/ripple/websocket/LogWebsockets.cpp index 597722dec..119ede18b 100644 --- a/src/ripple/websocket/LogWebsockets.cpp +++ b/src/ripple/websocket/LogWebsockets.cpp @@ -26,30 +26,33 @@ namespace log { void websocketLog ( websocketpp_02::log::alevel::value v, std::string const& entry) { - using namespace ripple; - auto isTrace = v == websocketpp_02::log::alevel::DEVEL || - v == websocketpp_02::log::alevel::DEBUG_CLOSE; + auto const isTrace = + v == websocketpp_02::log::alevel::DEVEL || + v == websocketpp_02::log::alevel::DEBUG_CLOSE; - WriteLog(isTrace ? lsTRACE : lsDEBUG, WebSocket) << entry; + auto journal = ripple::debugJournal(); + + if (isTrace) + JLOG (journal.trace) << entry; + else + JLOG (journal.debug) << entry; } void websocketLog ( websocketpp_02::log::elevel::value v, std::string const& entry) { - using namespace ripple; - - LogSeverity s = lsDEBUG; + auto journal = ripple::debugJournal(); if ((v & websocketpp_02::log::elevel::INFO) != 0) - s = lsINFO; + JLOG (journal.info) << entry; else if ((v & websocketpp_02::log::elevel::FATAL) != 0) - s = lsFATAL; + JLOG (journal.fatal) << entry; else if ((v & websocketpp_02::log::elevel::RERROR) != 0) - s = lsERROR; + JLOG (journal.error) << entry; else if ((v & websocketpp_02::log::elevel::WARN) != 0) - s = lsWARNING; - - WriteLog(s, WebSocket) << entry; + JLOG (journal.warning) << entry; + else + JLOG (journal.debug) << entry; } } diff --git a/src/ripple/websocket/Logger.h b/src/ripple/websocket/Logger.h deleted file mode 100644 index d331e115a..000000000 --- a/src/ripple/websocket/Logger.h +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLED_RIPPLE_WEBSOCKET_LOGGER_H -#define RIPPLED_RIPPLE_WEBSOCKET_LOGGER_H - -#include -#include - -namespace ripple { -namespace websocket { - -using LogLevel = websocketpp::log::level; -enum class LoggerType {error, access}; - -template -LogSeverity getSeverity (LogLevel); - -template -class Logger { -public: - using Hint = websocketpp::log::channel_type_hint::value; - - explicit Logger (Hint) {} - Logger (LogLevel, Hint) {} - void set_channels (LogLevel) {} - void clear_channels (LogLevel) {} - - void write (LogLevel level, std::string const& s) - { - WriteLog (getSeverity (level), WebSocket) << s; - } - - void write (LogLevel level, const char* s) - { - write (level, std::string (s)); - } - - bool static_test (LogLevel) const { - return true; - } - - bool dynamic_test (LogLevel) { - return true; - } -}; - -template <> -LogSeverity getSeverity (LogLevel level) -{ - if (level & websocketpp::log::elevel::info) - return lsINFO; - if (level & websocketpp::log::elevel::fatal) - return lsFATAL; - if (level & websocketpp::log::elevel::rerror) - return lsERROR; - if (level & websocketpp::log::elevel::warn) - return lsWARNING; - return lsDEBUG; -} - -template <> -LogSeverity getSeverity (LogLevel level) -{ - auto isTrace = level == websocketpp::log::alevel::devel || - level == websocketpp::log::alevel::debug_close; - - return isTrace ? lsTRACE : lsDEBUG; -} - -} // websocket -} // ripple - -#endif