Streamline Log with print() and out()

This commit is contained in:
Vinnie Falco
2013-06-30 12:11:42 -07:00
parent c35c52ff08
commit b52bbccd8a
25 changed files with 174 additions and 81 deletions

View File

@@ -2,6 +2,8 @@
RIPPLE TODO RIPPLE TODO
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- Make sure the leak detector output appears on Linux and FreeBSD debug builds.
- Create SharedData <LoadState>, move all load related state variables currently - Create SharedData <LoadState>, move all load related state variables currently
protected by separated mutexes in different classes into the LoadState, and protected by separated mutexes in different classes into the LoadState, and
use read/write locking semantics to update the values. Later, use Listeners use read/write locking semantics to update the values. Later, use Listeners

View File

@@ -62,13 +62,13 @@ Section ParseSection (const std::string& strInput, const bool bTrim)
void SectionEntriesPrint (std::vector<std::string>* vspEntries, const std::string& strSection) void SectionEntriesPrint (std::vector<std::string>* vspEntries, const std::string& strSection)
{ {
std::cerr << "[" << strSection << "]" << std::endl; Log::out() << "[" << strSection << "]";
if (vspEntries) if (vspEntries)
{ {
BOOST_FOREACH (std::string & strValue, *vspEntries) BOOST_FOREACH (std::string & strValue, *vspEntries)
{ {
std::cerr << strValue << std::endl; Log::out() << strValue;
} }
} }
} }

View File

@@ -139,13 +139,33 @@ Log::~Log ()
logMsg += "..."; logMsg += "...";
} }
print (logMsg, mSeverity >= sMinSeverity);
}
void Log::print (std::string const& text, bool toStdErr)
{
boost::recursive_mutex::scoped_lock sl (sLock); boost::recursive_mutex::scoped_lock sl (sLock);
if (mSeverity >= sMinSeverity) // Always write to the log file if it is open.
std::cerr << logMsg << std::endl; //
if (outStream != NULL) if (outStream != NULL)
(*outStream) << logMsg << std::endl; {
(*outStream) << text << std::endl;
}
if (toStdErr)
{
if (beast_isRunningUnderDebugger ())
{
// Send it to the attached debugger's Output window
//
Logger::outputDebugString (text);
}
else
{
std::cerr << text << std::endl;
}
}
} }
std::string Log::rotateLog (void) std::string Log::rotateLog (void)

View File

@@ -117,6 +117,63 @@ public:
static std::string rotateLog (); static std::string rotateLog ();
public:
/** Write to log output.
All logging eventually goes through this function. If a
debugger is attached, the string goes to the debugging console,
else it goes to the standard error output. If a log file is
open, then the message is additionally written to the open log
file.
The text should not contain a newline, it will be automatically
added as needed.
@note This acquires a global mutex.
@param text The text to write.
@param toStdErr `true` to also write to std::cerr
*/
static void print (std::string const& text,
bool toStdErr = true);
/** Output stream for logging
This is a convenient replacement for writing to `std::cerr`.
Usage:
@code
Log::out () << "item1" << 2;
@endcode
It is not necessary to append a newline.
*/
class out
{
public:
out ()
{
}
~out ()
{
Log::print (m_ss.str ());
}
template <class T>
out& operator<< (T t)
{
m_ss << t;
return *this;
}
private:
std::stringstream m_ss;
};
private: private:
enum enum
{ {

View File

@@ -37,7 +37,7 @@ void RandomNumbers::fillBytes (void* destinationBuffer, int numberOfBytes)
if (! initialize ()) if (! initialize ())
{ {
char const* message = "Unable to add system entropy"; char const* message = "Unable to add system entropy";
std::cerr << message << std::endl; Log::out() << message;
throw std::runtime_error (message); throw std::runtime_error (message);
} }
} }
@@ -75,7 +75,7 @@ bool RandomNumbers::platformAddEntropy ()
if (!CryptGetDefaultProviderA (PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, name, &count)) if (!CryptGetDefaultProviderA (PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, name, &count))
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Unable to get default crypto provider" << std::endl; Log::out() << "Unable to get default crypto provider";
#endif #endif
return false; return false;
} }
@@ -83,7 +83,7 @@ bool RandomNumbers::platformAddEntropy ()
if (!CryptAcquireContextA (&cryptoHandle, NULL, name, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) if (!CryptAcquireContextA (&cryptoHandle, NULL, name, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Unable to acquire crypto provider" << std::endl; Log::out() << "Unable to acquire crypto provider";
#endif #endif
return false; return false;
} }
@@ -91,7 +91,7 @@ bool RandomNumbers::platformAddEntropy ()
if (!CryptGenRandom (cryptoHandle, 128, reinterpret_cast<BYTE*> (rand))) if (!CryptGenRandom (cryptoHandle, 128, reinterpret_cast<BYTE*> (rand)))
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Unable to get entropy from crypto provider" << std::endl; Log::out() << "Unable to get entropy from crypto provider";
#endif #endif
CryptReleaseContext (cryptoHandle, 0); CryptReleaseContext (cryptoHandle, 0);
return false; return false;
@@ -115,7 +115,7 @@ bool RandomNumbers::platformAddEntropy ()
if (!reader.is_open ()) if (!reader.is_open ())
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Unable to open random source" << std::endl; Log::out() << "Unable to open random source";
#endif #endif
return false; return false;
} }
@@ -127,7 +127,7 @@ bool RandomNumbers::platformAddEntropy ()
if (bytesRead == 0) if (bytesRead == 0)
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Unable to read from random source" << std::endl; Log::out() << "Unable to read from random source";
#endif #endif
return false; return false;
} }

View File

@@ -188,6 +188,7 @@ extern std::string urlEncode (const std::string& strSrc)
// IP Port parsing // IP Port parsing
// //
// <-- iPort: "" = -1 // <-- iPort: "" = -1
// VFALCO TODO Make this not require boost... and especially boost::asio
bool parseIpPort (const std::string& strSource, std::string& strIP, int& iPort) bool parseIpPort (const std::string& strSource, std::string& strIP, int& iPort)
{ {
boost::smatch smMatch; boost::smatch smMatch;
@@ -235,10 +236,10 @@ bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& s
boost::algorithm::to_lower (strScheme); boost::algorithm::to_lower (strScheme);
iPort = strPort.empty () ? -1 : lexical_cast_s<int> (strPort); iPort = strPort.empty () ? -1 : lexical_cast_s<int> (strPort);
// std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPort << "' : " << iPort << " : '" << strPath << "'" << std::endl; // Log::out() << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPort << "' : " << iPort << " : '" << strPath << "'";
} }
// std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'" << std::endl; // Log::out() << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'";
return bMatch; return bMatch;
} }
@@ -261,3 +262,12 @@ bool parseQuality (const std::string& strSource, uint32& uQuality)
return !!uQuality; return !!uQuality;
} }
std::string addressToString (void const* address)
{
// VFALCO TODO Clean this up, use uintptr_t and only produce a 32 bit
// output on 32 bit platforms
//
return strHex (static_cast <char const*> (address) - static_cast <char const*> (0));
}

View File

@@ -208,6 +208,10 @@ template<typename T> std::string lexical_cast_it (const T& t)
bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath); bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath);
#endif #define ADDRESS(p) strHex(uint64( ((char*) p) - ((char*) 0)))
// vim:ts=4 /** Convert a pointer address to a string for display purposes.
*/
extern std::string addressToString (void const* address);
#endif

View File

@@ -197,9 +197,9 @@ void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet)
// Update default values // Update default values
load (); load ();
// std::cerr << "CONFIG FILE: " << CONFIG_FILE << std::endl; // Log::out() << "CONFIG FILE: " << CONFIG_FILE;
// std::cerr << "CONFIG DIR: " << CONFIG_DIR << std::endl; // Log::out() << "CONFIG DIR: " << CONFIG_DIR;
// std::cerr << "DATA DIR: " << DATA_DIR << std::endl; // Log::out() << "DATA DIR: " << DATA_DIR;
boost::filesystem::create_directories (DATA_DIR, ec); boost::filesystem::create_directories (DATA_DIR, ec);
@@ -274,13 +274,13 @@ Config::Config ()
void Config::load () void Config::load ()
{ {
if (!QUIET) if (!QUIET)
std::cerr << "Loading: " << CONFIG_FILE << std::endl; Log::out() << "Loading: " << CONFIG_FILE;
std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in); std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in);
if (!ifsConfig) if (!ifsConfig)
{ {
std::cerr << "Failed to open '" << CONFIG_FILE << "'." << std::endl; Log::out() << "Failed to open '" << CONFIG_FILE << "'.";
} }
else else
{ {
@@ -291,7 +291,7 @@ void Config::load ()
if (ifsConfig.bad ()) if (ifsConfig.bad ())
{ {
std::cerr << "Failed to read '" << CONFIG_FILE << "'." << std::endl; Log::out() << "Failed to read '" << CONFIG_FILE << "'.";
} }
else else
{ {

View File

@@ -277,7 +277,7 @@ bool checkECIES (void)
if ((i % 100) == 0) if ((i % 100) == 0)
{ {
// generate new keys every 100 times // generate new keys every 100 times
// std::cerr << "new keys" << std::endl; // Log::out() << "new keys";
senderPriv.MakeNewKey (); senderPriv.MakeNewKey ();
recipientPriv.MakeNewKey (); recipientPriv.MakeNewKey ();
@@ -307,7 +307,7 @@ bool checkECIES (void)
return false; return false;
} }
// std::cerr << "Msg(" << msglen << ") ok " << ciphertext.size() << std::endl; //Log::out() << "Msg(" << msglen << ") ok " << ciphertext.size();
} }
return true; return true;

View File

@@ -19,7 +19,7 @@ PackedMessage::PackedMessage (::google::protobuf::Message const& message, int ty
message.SerializeToArray (&mBuffer [PackedMessage::kHeaderBytes], messageBytes); message.SerializeToArray (&mBuffer [PackedMessage::kHeaderBytes], messageBytes);
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
// std::cerr << "PackedMessage: type=" << type << ", datalen=" << msg_size << std::endl; //Log::out() << "PackedMessage: type=" << type << ", datalen=" << msg_size;
#endif #endif
} }
} }

View File

@@ -814,17 +814,17 @@ bool RippleAddress::setSeedGeneric (const std::string& strText)
} }
else if (setSeed (strText)) else if (setSeed (strText))
{ {
// std::cerr << "Recognized seed." << std::endl; // Log::out() << "Recognized seed.";
nothing (); nothing ();
} }
else if (1 == setSeed1751 (strText)) else if (1 == setSeed1751 (strText))
{ {
// std::cerr << "Recognized 1751 seed." << std::endl; // Log::out() << "Recognized 1751 seed.";
nothing (); nothing ();
} }
else else
{ {
// std::cerr << "Creating seed from pass phrase." << std::endl; // Log::out() << "Creating seed from pass phrase.";
setSeed (CKey::PassPhraseToKey (strText)); setSeed (CKey::PassPhraseToKey (strText));
} }

View File

@@ -50,7 +50,7 @@ bool STAmount::currencyFromString (uint160& uDstCurrency, const std::string& sCu
// std::string sIso; // std::string sIso;
// sIso.assign(vucIso.begin(), vucIso.end()); // sIso.assign(vucIso.begin(), vucIso.end());
// std::cerr << "currency: " << sIso << std::endl; // Log::out() << "currency: " << sIso;
Serializer s; Serializer s;

View File

@@ -25,6 +25,8 @@ SerializedType& SerializedType::operator= (const SerializedType& t)
void STPathSet::printDebug () void STPathSet::printDebug ()
{ {
// VFALCO NOTE Can't use Log::out() because of std::endl
//
for (int i = 0; i < value.size (); i++) for (int i = 0; i < value.size (); i++)
{ {
std::cerr << i << ": "; std::cerr << i << ": ";
@@ -45,13 +47,13 @@ void STPathSet::printDebug ()
void STPath::printDebug () void STPath::printDebug ()
{ {
std::cerr << "STPath:" << std::endl; Log::out() << "STPath:";
for (int i = 0; i < mPath.size (); i++) for (int i = 0; i < mPath.size (); i++)
{ {
RippleAddress nad; RippleAddress nad;
nad.setAccountID (mPath[i].mAccountID); nad.setAccountID (mPath[i].mAccountID);
std::cerr << " " << i << ": " << nad.humanAccountID () << std::endl; Log::out() << " " << i << ": " << nad.humanAccountID ();
} }
} }

View File

@@ -1014,10 +1014,10 @@ void callRPC (
// Connect to localhost // Connect to localhost
if (!theConfig.QUIET) if (!theConfig.QUIET)
{ {
std::cerr << "Connecting to: " << strIp << ":" << iPort << std::endl; Log::out() << "Connecting to: " << strIp << ":" << iPort;
// std::cerr << "Username: " << strUsername << ":" << strPassword << std::endl; // Log::out() << "Username: " << strUsername << ":" << strPassword;
// std::cerr << "Path: " << strPath << std::endl; // Log::out() << "Path: " << strPath;
// std::cerr << "Method: " << strMethod << std::endl; // Log::out() << "Method: " << strMethod;
} }
// HTTP basic authentication // HTTP basic authentication

View File

@@ -268,7 +268,7 @@ bool Ledger::hasAccount (const RippleAddress& accountID)
AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID) AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID)
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
// std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl; // Log::out() << "Ledger:getAccountState(" << accountID.humanAccountID() << ")";
#endif #endif
SLE::pointer sle = getSLEi (Ledger::getAccountRootIndex (accountID)); SLE::pointer sle = getSLEi (Ledger::getAccountRootIndex (accountID));

View File

@@ -275,9 +275,9 @@ Json::Value RPCHandler::transactionSign (Json::Value params, bool bSubmit, bool
// ... or the master key must have been used. // ... or the master key must have been used.
&& raSrcAddressID.getAccountID () != naAccountPublic.getAccountID ()) && raSrcAddressID.getAccountID () != naAccountPublic.getAccountID ())
{ {
// std::cerr << "iIndex: " << iIndex << std::endl; // Log::out() << "iIndex: " << iIndex;
// std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl; // Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID());
// std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl; // Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID());
return rpcError (rpcSRC_ACT_NOT_FOUND); return rpcError (rpcSRC_ACT_NOT_FOUND);
} }
@@ -493,9 +493,9 @@ Json::Value RPCHandler::authorize (Ledger::ref lrLedger,
if (asSrc->haveAuthorizedKey () && (asSrc->getAuthorizedKey ().getAccountID () != naAccountPublic.getAccountID ())) if (asSrc->haveAuthorizedKey () && (asSrc->getAuthorizedKey ().getAccountID () != naAccountPublic.getAccountID ()))
{ {
// std::cerr << "iIndex: " << iIndex << std::endl; // Log::out() << "iIndex: " << iIndex;
// std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl; // Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID());
// std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl; // Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID());
return rpcError (rpcPASSWD_CHANGED); return rpcError (rpcPASSWD_CHANGED);
} }
@@ -2113,7 +2113,7 @@ Json::Value RPCHandler::doValidationSeed (Json::Value params, LoadType* loadType
if (!params.isMember ("secret")) if (!params.isMember ("secret"))
{ {
std::cerr << "Unset validation seed." << std::endl; Log::out() << "Unset validation seed.";
theConfig.VALIDATION_SEED.clear (); theConfig.VALIDATION_SEED.clear ();
theConfig.VALIDATION_PUB.clear (); theConfig.VALIDATION_PUB.clear ();

View File

@@ -18,7 +18,7 @@ RPCServer::RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::con
void RPCServer::connected () void RPCServer::connected ()
{ {
//std::cerr << "RPC request" << std::endl; //Log::out() << "RPC request";
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n", boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error))); mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error)));
} }
@@ -178,7 +178,7 @@ bool RPCServer::parseAcceptRate (const std::string& sAcceptRate)
void RPCServer::handle_write (const boost::system::error_code& e) void RPCServer::handle_write (const boost::system::error_code& e)
{ {
//std::cerr << "async_write complete " << e << std::endl; //Log::out() << "async_write complete " << e;
if (!e) if (!e)
{ {

View File

@@ -22,7 +22,7 @@ uint64 RegularKeySetTransactor::calculateBaseFee ()
TER RegularKeySetTransactor::doApply () TER RegularKeySetTransactor::doApply ()
{ {
std::cerr << "RegularKeySet>" << std::endl; Log::out() << "RegularKeySet>";
const uint32 uTxFlags = mTxn.getFlags (); const uint32 uTxFlags = mTxn.getFlags ();
@@ -50,7 +50,7 @@ TER RegularKeySetTransactor::doApply ()
mTxnAccount->makeFieldAbsent (sfRegularKey); mTxnAccount->makeFieldAbsent (sfRegularKey);
} }
std::cerr << "RegularKeySet<" << std::endl; Log::out() << "RegularKeySet<";
return tesSUCCESS; return tesSUCCESS;
} }

View File

@@ -8,7 +8,7 @@ SETUP_LOG (WalletAddTransactor)
TER WalletAddTransactor::doApply () TER WalletAddTransactor::doApply ()
{ {
std::cerr << "WalletAdd>" << std::endl; Log::out() << "WalletAdd>";
Blob const vucPubKey = mTxn.getFieldVL (sfPublicKey); Blob const vucPubKey = mTxn.getFieldVL (sfPublicKey);
Blob const vucSignature = mTxn.getFieldVL (sfSignature); Blob const vucSignature = mTxn.getFieldVL (sfSignature);
@@ -28,7 +28,7 @@ TER WalletAddTransactor::doApply ()
// FIXME: This should be moved to the transaction's signature check logic and cached // FIXME: This should be moved to the transaction's signature check logic and cached
if (!naMasterPubKey.accountPublicVerify (Serializer::getSHA512Half (uAuthKeyID.begin (), uAuthKeyID.size ()), vucSignature)) if (!naMasterPubKey.accountPublicVerify (Serializer::getSHA512Half (uAuthKeyID.begin (), uAuthKeyID.size ()), vucSignature))
{ {
std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; Log::out() << "WalletAdd: unauthorized: bad signature ";
return tefBAD_ADD_AUTH; return tefBAD_ADD_AUTH;
} }
@@ -37,7 +37,7 @@ TER WalletAddTransactor::doApply ()
if (sleDst) if (sleDst)
{ {
std::cerr << "WalletAdd: account already created" << std::endl; Log::out() << "WalletAdd: account already created";
return tefCREATED; return tefCREATED;
} }
@@ -71,7 +71,7 @@ TER WalletAddTransactor::doApply ()
sleDst->setFieldAmount (sfBalance, saDstAmount); sleDst->setFieldAmount (sfBalance, saDstAmount);
sleDst->setFieldAccount (sfRegularKey, uAuthKeyID); sleDst->setFieldAccount (sfRegularKey, uAuthKeyID);
std::cerr << "WalletAdd<" << std::endl; Log::out() << "WalletAdd<";
return tesSUCCESS; return tesSUCCESS;
} }

View File

@@ -24,7 +24,7 @@ void LocalCredentials::start ()
} }
if (!theConfig.QUIET) if (!theConfig.QUIET)
std::cerr << "NodeIdentity: " << mNodePublicKey.humanNodePublic () << std::endl; Log::out() << "NodeIdentity: " << mNodePublicKey.humanNodePublic ();
getApp().getUNL ().start (); getApp().getUNL ().start ();
} }
@@ -67,7 +67,7 @@ bool LocalCredentials::nodeIdentityLoad ()
bool LocalCredentials::nodeIdentityCreate () bool LocalCredentials::nodeIdentityCreate ()
{ {
if (!theConfig.QUIET) if (!theConfig.QUIET)
std::cerr << "NodeIdentity: Creating." << std::endl; Log::out() << "NodeIdentity: Creating.";
// //
// Generate the public and private key // Generate the public and private key
@@ -114,7 +114,7 @@ bool LocalCredentials::nodeIdentityCreate ()
// XXX Check error result. // XXX Check error result.
if (!theConfig.QUIET) if (!theConfig.QUIET)
std::cerr << "NodeIdentity: Created." << std::endl; Log::out() << "NodeIdentity: Created.";
return true; return true;
} }

View File

@@ -26,7 +26,7 @@ void startServer ()
const Json::Value& jvCommand = theConfig.RPC_STARTUP[i]; const Json::Value& jvCommand = theConfig.RPC_STARTUP[i];
if (!theConfig.QUIET) if (!theConfig.QUIET)
std::cerr << "Startup RPC: " << jvCommand << std::endl; Log::out() << "Startup RPC: " << jvCommand;
RPCHandler rhHandler (&getApp().getOPs ()); RPCHandler rhHandler (&getApp().getOPs ());
@@ -35,7 +35,7 @@ void startServer ()
Json::Value jvResult = rhHandler.doCommand (jvCommand, RPCHandler::ADMIN, &loadType); Json::Value jvResult = rhHandler.doCommand (jvCommand, RPCHandler::ADMIN, &loadType);
if (!theConfig.QUIET) if (!theConfig.QUIET)
std::cerr << "Result: " << jvResult << std::endl; Log::out() << "Result: " << jvResult;
} }
} }
@@ -187,7 +187,7 @@ int rippleMain (int argc, char** argv)
if (! RandomNumbers::getInstance ().initialize ()) if (! RandomNumbers::getInstance ().initialize ())
{ {
std::cerr << "Unable to add system entropy" << std::endl; Log::out() << "Unable to add system entropy";
iResult = 2; iResult = 2;
} }

View File

@@ -4,9 +4,6 @@
*/ */
//============================================================================== //==============================================================================
// VFALCO TODO make this an inline function
#define ADDRESS(p) strHex(uint64( ((char*) p) - ((char*) 0)))
SETUP_LOG (Peer) SETUP_LOG (Peer)
class PeerImp; class PeerImp;
@@ -207,7 +204,7 @@ PeerImp::PeerImp (boost::asio::io_service& io_service, boost::asio::ssl::context
mActivityTimer (io_service), mActivityTimer (io_service),
mIOStrand (io_service) mIOStrand (io_service)
{ {
WriteLog (lsDEBUG, Peer) << "CREATING PEER: " << ADDRESS (this); WriteLog (lsDEBUG, Peer) << "CREATING PEER: " << addressToString (this);
} }
void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_transferred) void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_transferred)
@@ -215,7 +212,7 @@ void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_
// Call on IO strand // Call on IO strand
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
// if (!error) // if (!error)
// std::cerr << "PeerImp::handleWrite bytes: "<< bytes_transferred << std::endl; // Log::out() << "PeerImp::handleWrite bytes: "<< bytes_transferred;
#endif #endif
mSendingPacket.reset (); mSendingPacket.reset ();
@@ -227,7 +224,7 @@ void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_
} }
else if (error) else if (error)
{ {
WriteLog (lsINFO, Peer) << "Peer: Write: Error: " << ADDRESS (this) << ": bytes=" << bytes_transferred << ": " << error.category ().name () << ": " << error.message () << ": " << error; WriteLog (lsINFO, Peer) << "Peer: Write: Error: " << addressToString (this) << ": bytes=" << bytes_transferred << ": " << error.category ().name () << ": " << error.message () << ": " << error;
detach ("hw", true); detach ("hw", true);
} }
@@ -249,7 +246,7 @@ void PeerImp::setIpPort (const std::string& strIP, int iPort)
mLoad.rename (strIP); mLoad.rename (strIP);
WriteLog (lsDEBUG, Peer) << "Peer: Set: " WriteLog (lsDEBUG, Peer) << "Peer: Set: "
<< ADDRESS (this) << "> " << addressToString (this) << "> "
<< (mNodePublic.isValid () ? mNodePublic.humanNodePublic () : "-") << " " << getIP () << " " << getPort (); << (mNodePublic.isValid () ? mNodePublic.humanNodePublic () : "-") << " " << getIP () << " " << getPort ();
} }
@@ -272,7 +269,7 @@ void PeerImp::detach (const char* rsn, bool onIOStrand)
CondLog (mCluster, lsWARNING, Peer) << "Cluster peer detach \"" << mNodeName << "\": " << rsn; CondLog (mCluster, lsWARNING, Peer) << "Cluster peer detach \"" << mNodeName << "\": " << rsn;
/* /*
WriteLog (lsDEBUG, Peer) << "Peer: Detach: " WriteLog (lsDEBUG, Peer) << "Peer: Detach: "
<< ADDRESS(this) << "> " << addressToString(this) << "> "
<< rsn << ": " << rsn << ": "
<< (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort(); << (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort();
*/ */
@@ -302,7 +299,7 @@ void PeerImp::detach (const char* rsn, bool onIOStrand)
/* /*
WriteLog (lsDEBUG, Peer) << "Peer: Detach: " WriteLog (lsDEBUG, Peer) << "Peer: Detach: "
<< ADDRESS(this) << "< " << addressToString(this) << "< "
<< rsn << ": " << rsn << ": "
<< (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort(); << (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort();
*/ */
@@ -346,7 +343,7 @@ void PeerImp::handleVerifyTimer (const boost::system::error_code& ecResult)
if (ecResult == boost::asio::error::operation_aborted) if (ecResult == boost::asio::error::operation_aborted)
{ {
// Timer canceled because deadline no longer needed. // Timer canceled because deadline no longer needed.
// std::cerr << "Deadline cancelled." << std::endl; // Log::out() << "Deadline cancelled.";
nothing (); // Aborter is done. nothing (); // Aborter is done.
} }
@@ -405,7 +402,7 @@ void PeerImp::connect (const std::string& strIp, int iPort)
if (!err) if (!err)
{ {
WriteLog (lsINFO, Peer) << "Peer: Connect: Outbound: " << ADDRESS (this) << ": " << mIpPort.first << " " << mIpPort.second; WriteLog (lsINFO, Peer) << "Peer: Connect: Outbound: " << addressToString (this) << ": " << mIpPort.first << " " << mIpPort.second;
boost::asio::async_connect ( boost::asio::async_connect (
getSocket (), getSocket (),
@@ -488,7 +485,7 @@ void PeerImp::connected (const boost::system::error_code& error)
{ {
// Not redundant ip and port, handshake, and start. // Not redundant ip and port, handshake, and start.
WriteLog (lsINFO, Peer) << "Peer: Inbound: Accepted: " << ADDRESS (this) << ": " << strIp << " " << iPort; WriteLog (lsINFO, Peer) << "Peer: Inbound: Accepted: " << addressToString (this) << ": " << strIp << " " << iPort;
mSocketSsl.set_verify_mode (boost::asio::ssl::verify_none); mSocketSsl.set_verify_mode (boost::asio::ssl::verify_none);
@@ -498,7 +495,7 @@ void PeerImp::connected (const boost::system::error_code& error)
} }
else if (!mDetaching) else if (!mDetaching)
{ {
WriteLog (lsINFO, Peer) << "Peer: Inbound: Error: " << ADDRESS (this) << ": " << strIp << " " << iPort << " : " << error.category ().name () << ": " << error.message () << ": " << error; WriteLog (lsINFO, Peer) << "Peer: Inbound: Error: " << addressToString (this) << ": " << strIp << " " << iPort << " : " << error.category ().name () << ": " << error.message () << ": " << error;
detach ("ctd", false); detach ("ctd", false);
} }
@@ -641,10 +638,10 @@ void PeerImp::processReadBuffer ()
// must not hold peer lock // must not hold peer lock
int type = PackedMessage::getType (mReadbuf); int type = PackedMessage::getType (mReadbuf);
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
// std::cerr << "PRB(" << type << "), len=" << (mReadbuf.size()-PackedMessage::kHeaderBytes) << std::endl; // Log::out() << "PRB(" << type << "), len=" << (mReadbuf.size()-PackedMessage::kHeaderBytes);
#endif #endif
// std::cerr << "PeerImp::processReadBuffer: " << mIpPort.first << " " << mIpPort.second << std::endl; // Log::out() << "PeerImp::processReadBuffer: " << mIpPort.first << " " << mIpPort.second;
LoadEvent::autoptr event (getApp().getJobQueue ().getLoadEventAP (jtPEER, "PeerImp::read")); LoadEvent::autoptr event (getApp().getJobQueue ().getLoadEventAP (jtPEER, "PeerImp::read"));
@@ -1136,8 +1133,9 @@ void PeerImp::recvTransaction (protocol::TMTransaction& packet, ScopedLock& Mast
catch (...) catch (...)
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Transaction from peer fails validity tests" << std::endl; Log::out() << "Transaction from peer fails validity tests";
Json::StyledStreamWriter w; Json::StyledStreamWriter w;
// VFALCO NOTE This bypasses the Log bottleneck
w.write (std::cerr, tx->getJson (0)); w.write (std::cerr, tx->getJson (0));
#endif #endif
return; return;
@@ -1430,7 +1428,7 @@ void PeerImp::recvGetPeers (protocol::TMGetPeers& packet, ScopedLock& MasterLock
addr->set_ipv4 (inet_addr (strIP.c_str ())); addr->set_ipv4 (inet_addr (strIP.c_str ()));
addr->set_ipv4port (iPort); addr->set_ipv4port (iPort);
//WriteLog (lsINFO, Peer) << "Peer: Teaching: " << ADDRESS(this) << ": " << n << ": " << strIP << " " << iPort; //WriteLog (lsINFO, Peer) << "Peer: Teaching: " << addressToString(this) << ": " << n << ": " << strIP << " " << iPort;
} }
PackedMessage::pointer message = boost::make_shared<PackedMessage> (peers, protocol::mtPEERS); PackedMessage::pointer message = boost::make_shared<PackedMessage> (peers, protocol::mtPEERS);
@@ -1452,7 +1450,7 @@ void PeerImp::recvPeers (protocol::TMPeers& packet)
if (strIP != "0.0.0.0" && strIP != "127.0.0.1") if (strIP != "0.0.0.0" && strIP != "127.0.0.1")
{ {
//WriteLog (lsINFO, Peer) << "Peer: Learning: " << ADDRESS(this) << ": " << i << ": " << strIP << " " << iPort; //WriteLog (lsINFO, Peer) << "Peer: Learning: " << addressToString(this) << ": " << i << ": " << strIP << " " << iPort;
getApp().getPeers ().savePeer (strIP, iPort, IUniqueNodeList::vsTold); getApp().getPeers ().savePeer (strIP, iPort, IUniqueNodeList::vsTold);
} }
@@ -2310,7 +2308,7 @@ Json::Value PeerImp::getJson ()
{ {
Json::Value ret (Json::objectValue); Json::Value ret (Json::objectValue);
//ret["this"] = ADDRESS(this); //ret["this"] = addressToString(this);
ret["public_key"] = mNodePublic.ToString (); ret["public_key"] = mNodePublic.ToString ();
ret["ip"] = mIpPortConnect.first; ret["ip"] = mIpPortConnect.first;
//ret["port"] = mIpPortConnect.second; //ret["port"] = mIpPortConnect.second;

View File

@@ -196,7 +196,7 @@ bool Peers::savePeer (const std::string& strIp, int iPort, char code)
} }
else else
{ {
std::cerr << "Error saving Peer" << std::endl; Log::out() << "Error saving Peer";
} }
if (bNew) if (bNew)

View File

@@ -138,8 +138,8 @@ int SHAMapNode::selectBranch (uint256 const& hash) const
if ((hash & smMasks[mDepth]) != mNodeID) if ((hash & smMasks[mDepth]) != mNodeID)
{ {
std::cerr << "selectBranch(" << getString () << std::endl; Log::out() << "selectBranch(" << getString ();
std::cerr << " " << hash << " off branch" << std::endl; Log::out() << " " << hash << " off branch";
assert (false); assert (false);
return -1; // does not go under this node return -1; // does not go under this node
} }

View File

@@ -38,8 +38,8 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, uint3
if ((type < 0) || (type > 4)) if ((type < 0) || (type > 4))
{ {
#ifdef BEAST_DEBUG #ifdef BEAST_DEBUG
std::cerr << "Invalid wire format node" << std::endl; Log::out() << "Invalid wire format node";
std::cerr << strHex (rawNode) << std::endl; Log::out() << strHex (rawNode);
assert (false); assert (false);
#endif #endif
throw std::runtime_error ("invalid node AW type"); throw std::runtime_error ("invalid node AW type");