From 220331394522ec566c3f3030db90b766200948ce Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 18 Dec 2012 14:39:02 -0800 Subject: [PATCH] Logging cleanups. --- src/cpp/ripple/Amount.cpp | 26 ++++++++++----------- src/cpp/ripple/LedgerConsensus.cpp | 4 ++-- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/SHAMap.cpp | 12 +++++----- src/cpp/ripple/SHAMapNodes.cpp | 12 ++++++---- src/cpp/ripple/SNTPClient.cpp | 36 ++++++++++++++--------------- src/cpp/ripple/SerializedLedger.cpp | 7 +++--- src/cpp/ripple/WSDoor.cpp | 8 +++---- 8 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index c1e441621..8a3038fc2 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -277,7 +277,7 @@ bool STAmount::setValue(const std::string& sAmount) } catch (...) { - Log(lsINFO) << "Bad integer amount: " << sAmount; + cLog(lsINFO) << "Bad integer amount: " << sAmount; return false; } @@ -304,7 +304,7 @@ bool STAmount::setValue(const std::string& sAmount) } catch (...) { - Log(lsINFO) << "Bad e amount: " << sAmount; + cLog(lsINFO) << "Bad e amount: " << sAmount; return false; } @@ -346,7 +346,7 @@ bool STAmount::setValue(const std::string& sAmount) } catch (...) { - Log(lsINFO) << "Bad float amount: " << sAmount; + cLog(lsINFO) << "Bad float amount: " << sAmount; return false; } @@ -391,7 +391,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // if (!currencyFromString(mCurrency, sCurrency)) { - Log(lsINFO) << "Currency malformed: " << sCurrency; + cLog(lsINFO) << "Currency malformed: " << sCurrency; return false; } @@ -406,7 +406,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // Issuer must be "" or a valid account string. if (!naIssuerID.setAccountID(sIssuer)) { - Log(lsINFO) << "Issuer malformed: " << sIssuer; + cLog(lsINFO) << "Issuer malformed: " << sIssuer; return false; } @@ -416,7 +416,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // Stamps not must have an issuer. if (mIsNative && !mIssuer.isZero()) { - Log(lsINFO) << "Issuer specified for XRP: " << sIssuer; + cLog(lsINFO) << "Issuer specified for XRP: " << sIssuer; return false; } @@ -1050,7 +1050,7 @@ bool STAmount::applyOffer( saTakerPaid = saOfferGets; // Taker paid what offer could get. saTakerGot = saOfferPays; // Taker got what offer could pay. - Log(lsINFO) << "applyOffer: took all outright"; + cLog(lsINFO) << "applyOffer: took all outright"; } else if (saTakerFunds >= saOfferGetsAvailable) { @@ -1058,7 +1058,7 @@ bool STAmount::applyOffer( saTakerPaid = saOfferGetsAvailable; // Taker paid what offer could get. saTakerGot = saOfferPaysAvailable; // Taker got what offer could pay. - Log(lsINFO) << "applyOffer: took all available"; + cLog(lsINFO) << "applyOffer: took all available"; } else { @@ -1066,8 +1066,8 @@ bool STAmount::applyOffer( saTakerPaid = saTakerFunds; // Taker paid all he had. saTakerGot = divide(multiply(saTakerFunds, saOfferPaysAvailable, CURRENCY_ONE, ACCOUNT_ONE), saOfferGetsAvailable, saOfferPays.getCurrency(), saOfferPays.getIssuer()); - Log(lsINFO) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); - Log(lsINFO) << "applyOffer: saOfferPaysAvailable=" << saOfferPaysAvailable.getFullText(); + cLog(lsINFO) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); + cLog(lsINFO) << "applyOffer: saOfferPaysAvailable=" << saOfferPaysAvailable.getFullText(); } if (uTakerPaysRate == QUALITY_ONE) @@ -1394,7 +1394,7 @@ BOOST_AUTO_TEST_CASE( CustomCurrency_test ) BOOST_FAIL("STAmount multiply fail"); if (STAmount::divide(STAmount(CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount(3), CURRENCY_ONE, ACCOUNT_ONE).getText() != "20") { - Log(lsFATAL) << "60/3 = " << + cLog(lsFATAL) << "60/3 = " << STAmount::divide(STAmount(CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount(3), CURRENCY_ONE, ACCOUNT_ONE).getText(); BOOST_FAIL("STAmount divide fail"); @@ -1449,7 +1449,7 @@ static void mulTest(int a, int b) STAmount prod2(CURRENCY_ONE, ACCOUNT_ONE, static_cast(a) * static_cast(b)); if (prod1 != prod2) { - Log(lsWARNING) << "nn(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() + cLog(lsWARNING) << "nn(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() << " not " << prod2.getFullText(); BOOST_WARN("Multiplication result is not exact"); } @@ -1457,7 +1457,7 @@ static void mulTest(int a, int b) prod1 = STAmount::multiply(aa, bb, CURRENCY_ONE, ACCOUNT_ONE); if (prod1 != prod2) { - Log(lsWARNING) << "n(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() + cLog(lsWARNING) << "n(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() << " not " << prod2.getFullText(); BOOST_WARN("Multiplication result is not exact"); } diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index a06edc4ad..7953a1146 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -1232,10 +1232,10 @@ void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer) if (sLog(lsTRACE)) { - Log(lsTRACE) << "newLCL"; + cLog(lsTRACE) << "newLCL"; Json::Value p; newLCL->addJson(p, LEDGER_JSON_DUMP_TXRP | LEDGER_JSON_DUMP_STATE); - Log(lsTRACE) << p; + cLog(lsTRACE) << p; } statusChange(ripple::neACCEPTED_LEDGER, *newLCL); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 98a003c4a..ee5f63b14 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1006,7 +1006,7 @@ Json::Value RPCHandler::doSubmit(Json::Value jvRequest) { naMasterAccountPublic.setAccountPublic(naMasterGenerator, iIndex); - Log(lsWARNING) << "authorize: " << iIndex << " : " << naMasterAccountPublic.humanAccountID() << " : " << raSrcAddressID.humanAccountID(); + cLog(lsWARNING) << "authorize: " << iIndex << " : " << naMasterAccountPublic.humanAccountID() << " : " << raSrcAddressID.humanAccountID(); bFound = raSrcAddressID.getAccountID() == naMasterAccountPublic.getAccountID(); if (!bFound) diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index 4c83e1f0f..8d68fff13 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -707,7 +707,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui HashedObject::pointer obj(theApp->getHashedObjectStore().retrieve(hash)); if (!obj) { -// Log(lsTRACE) << "fetchNodeExternal: missing " << hash; +// cLog(lsTRACE) << "fetchNodeExternal: missing " << hash; throw SHAMapMissingNode(mType, id, hash); } @@ -716,13 +716,13 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui SHAMapTreeNode::pointer ret = boost::make_shared(id, obj->getData(), mSeq - 1, snfPREFIX); if (id != *ret) { - Log(lsFATAL) << "id:" << id << ", got:" << *ret; + cLog(lsFATAL) << "id:" << id << ", got:" << *ret; assert(false); return SHAMapTreeNode::pointer(); } if (ret->getNodeHash() != hash) { - Log(lsFATAL) << "Hashes don't match"; + cLog(lsFATAL) << "Hashes don't match"; assert(false); return SHAMapTreeNode::pointer(); } @@ -745,11 +745,11 @@ void SHAMap::fetchRoot(const uint256& hash) if (sLog(lsTRACE)) { if (mType == smtTRANSACTION) - Log(lsTRACE) << "Fetch root TXN node " << hash; + cLog(lsTRACE) << "Fetch root TXN node " << hash; else if (mType == smtSTATE) - Log(lsTRACE) << "Fetch root STATE node " << hash; + cLog(lsTRACE) << "Fetch root STATE node " << hash; else - Log(lsTRACE) << "Fetch root SHAMap node " << hash; + cLog(lsTRACE) << "Fetch root SHAMap node " << hash; } root = fetchNodeExternal(SHAMapNode(), hash); assert(root->getNodeHash() == hash); diff --git a/src/cpp/ripple/SHAMapNodes.cpp b/src/cpp/ripple/SHAMapNodes.cpp index a296c54f7..5d6877805 100644 --- a/src/cpp/ripple/SHAMapNodes.cpp +++ b/src/cpp/ripple/SHAMapNodes.cpp @@ -16,6 +16,8 @@ #include "Log.h" #include "HashPrefixes.h" +SETUP_LOG(); + std::string SHAMapNode::getString() const { static boost::format NodeID("NodeID(%s,%s)"); @@ -170,7 +172,7 @@ int SHAMapNode::selectBranch(const uint256& hash) const void SHAMapNode::dump() const { - Log(lsDEBUG) << getString(); + cLog(lsDEBUG) << getString(); } SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0), @@ -265,7 +267,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector(u, s.peekData()); @@ -313,7 +315,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector::iterator query = mQueries.find(mReceiveEndpoint); if (query == mQueries.end()) - Log(lsDEBUG) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query"; + cLog(lsDEBUG) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query"; else if (query->second.mReceivedReply) - Log(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint; + cLog(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint; else { query->second.mReceivedReply = true; if (time(NULL) > (query->second.mLocalTimeSent + 1)) - Log(lsWARNING) << "SNTP: Late response from " << mReceiveEndpoint; + cLog(lsWARNING) << "SNTP: Late response from " << mReceiveEndpoint; else if (bytes_xferd < 48) - Log(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint + cLog(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint << " (" << bytes_xferd << ") " << mReceiveBuffer.size(); else if (reinterpret_cast(&mReceiveBuffer[0])[NTP_OFF_ORGTS_FRAC] != query->second.mQueryNonce) - Log(lsWARNING) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce"; + cLog(lsWARNING) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce"; else processReply(); } @@ -123,8 +125,7 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size void SNTPClient::sendComplete(const boost::system::error_code& error, std::size_t) { - if (error) - Log(lsWARNING) << "SNTP: Send error"; + tLog(error, lsWARNING) << "SNTP: Send error"; } void SNTPClient::processReply() @@ -138,12 +139,12 @@ void SNTPClient::processReply() if ((info >> 30) == 3) { - Log(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint; + cLog(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint; return; } if ((stratum == 0) || (stratum > 14)) { - Log(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint; + cLog(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint; return; } @@ -171,10 +172,7 @@ void SNTPClient::processReply() if ((mOffset == -1) || (mOffset == 1)) // small corrections likely do more harm than good mOffset = 0; -#ifndef SNTP_DEBUG - if (timev || mOffset) -#endif - Log(lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset; + tLog(timev || mOffset, lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset; } void SNTPClient::timerEntry(const boost::system::error_code& error) @@ -198,7 +196,7 @@ void SNTPClient::init(const std::vector& servers) std::vector::const_iterator it = servers.begin(); if (it == servers.end()) { - Log(lsINFO) << "SNTP: no server specified"; + cLog(lsINFO) << "SNTP: no server specified"; return; } BOOST_FOREACH(const std::string& it, servers) @@ -231,13 +229,13 @@ bool SNTPClient::doQuery() best = it; if (best == mServers.end()) { - Log(lsINFO) << "SNTP: No server to query"; + cLog(lsINFO) << "SNTP: No server to query"; return false; } time_t now = time(NULL); if ((best->second != (time_t) -1) && ((best->second + NTP_MIN_QUERY) >= now)) { - Log(lsTRACE) << "SNTP: All servers recently queried"; + cLog(lsTRACE) << "SNTP: All servers recently queried"; return false; } best->second = now; @@ -247,7 +245,7 @@ bool SNTPClient::doQuery() boost::bind(&SNTPClient::resolveComplete, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator)); #ifdef SNTP_DEBUG - Log(lsTRACE) << "SNTP: Resolve pending for " << best->first; + cLog(lsTRACE) << "SNTP: Resolve pending for " << best->first; #endif return true; } diff --git a/src/cpp/ripple/SerializedLedger.cpp b/src/cpp/ripple/SerializedLedger.cpp index 9f70f7c52..8d6804a4d 100644 --- a/src/cpp/ripple/SerializedLedger.cpp +++ b/src/cpp/ripple/SerializedLedger.cpp @@ -6,6 +6,7 @@ #include "Log.h" DECLARE_INSTANCE(SerializedLedgerEntry) +SETUP_LOG(); SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) : STObject(sfLedgerEntry), mIndex(index) @@ -33,8 +34,8 @@ SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256& mType = mFormat->t_type; if (!setType(mFormat->elements)) { - Log(lsWARNING) << "Ledger entry not valid for type " << mFormat->t_name; - Log(lsWARNING) << getJson(0); + cLog(lsWARNING) << "Ledger entry not valid for type " << mFormat->t_name; + cLog(lsWARNING) << getJson(0); throw std::runtime_error("ledger entry not valid for type"); } } @@ -99,7 +100,7 @@ uint32 SerializedLedgerEntry::getThreadedLedger() bool SerializedLedgerEntry::thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID) { uint256 oldPrevTxID = getFieldH256(sfPreviousTxnID); - Log(lsTRACE) << "Thread Tx:" << txID << " prev:" << oldPrevTxID; + cLog(lsTRACE) << "Thread Tx:" << txID << " prev:" << oldPrevTxID; if (oldPrevTxID == txID) { // this transaction is already threaded assert(getFieldU32(sfPreviousTxnLgrSeq) == ledgerSeq); diff --git a/src/cpp/ripple/WSDoor.cpp b/src/cpp/ripple/WSDoor.cpp index cd523c0de..a992d667c 100644 --- a/src/cpp/ripple/WSDoor.cpp +++ b/src/cpp/ripple/WSDoor.cpp @@ -78,7 +78,7 @@ void WSDoor::startListening() } catch (websocketpp::exception& e) { - Log(lsWARNING) << "websocketpp exception: " << e.what(); + cLog(lsWARNING) << "websocketpp exception: " << e.what(); while (1) // temporary workaround for websocketpp throwing exceptions on access/close races { // https://github.com/zaphoyd/websocketpp/issues/98 try @@ -88,7 +88,7 @@ void WSDoor::startListening() } catch (websocketpp::exception& e) { - Log(lsWARNING) << "websocketpp exception: " << e.what(); + cLog(lsWARNING) << "websocketpp exception: " << e.what(); } } } @@ -114,7 +114,7 @@ void WSDoor::startListening() } catch (websocketpp::exception& e) { - Log(lsWARNING) << "websocketpp exception: " << e.what(); + cLog(lsWARNING) << "websocketpp exception: " << e.what(); while (1) // temporary workaround for websocketpp throwing exceptions on access/close races { // https://github.com/zaphoyd/websocketpp/issues/98 try @@ -124,7 +124,7 @@ void WSDoor::startListening() } catch (websocketpp::exception& e) { - Log(lsWARNING) << "websocketpp exception: " << e.what(); + cLog(lsWARNING) << "websocketpp exception: " << e.what(); } } }