diff --git a/newcoind.cfg b/newcoind.cfg index b97fef5f2a..bc846fa14c 100644 --- a/newcoind.cfg +++ b/newcoind.cfg @@ -31,6 +31,11 @@ # Note: $XDG_CONFIG_HOME defaults to $HOME/.config # $XDG_DATA_HOME defaults to $HOME/.local/share # +# [debug_logfile] +# Specifies were a debug logfile is kept. By default, no debug log is kept +# +# Example: debug.log +# # [validators_site]: # Specifies where to find validators.txt for UNL boostrapping and RPC command unl_network. # During alpha testing, this defaults to: redstem.com @@ -117,6 +122,9 @@ [rpc_allow_remote] 1 +[debug_logfile] +debug.log + [validation_seed] snTBDmrhUK3znvF8AaQURLm4UCkbS diff --git a/src/Application.cpp b/src/Application.cpp index 9e4cdd5ec8..4300f0bf4b 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -12,6 +12,7 @@ #include "utils.h" #include "TaggedCache.h" #include "boost/filesystem.hpp" +#include "Log.h" Application* theApp = NULL; @@ -53,7 +54,9 @@ void Application::stop() void Application::run() { - assert(mTxnDB==NULL); + assert(mTxnDB == NULL); + if (!theConfig.DEBUG_LOGFILE.empty()) + Log::setLogFile(theConfig.DEBUG_LOGFILE); // // Construct databases. diff --git a/src/Config.cpp b/src/Config.cpp index f399b05965..be65c19846 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -7,6 +7,7 @@ #include #define SECTION_ACCOUNT_PROBE_MAX "account_probe_max" +#define SECTION_DEBUG_LOGFILE "debug_logfile" #define SECTION_FEE_ACCOUNT_CREATE "fee_account_create" #define SECTION_FEE_DEFAULT "fee_default" #define SECTION_FEE_NICKNAME_CREATE "fee_nickname_create" @@ -233,6 +234,9 @@ void Config::load() if (sectionSingleB(secConfig, SECTION_UNL_DEFAULT, strTemp)) UNL_DEFAULT = strTemp; + + if (sectionSingleB(secConfig, SECTION_DEBUG_LOGFILE, strTemp)) + DEBUG_LOGFILE = strTemp; } } } diff --git a/src/Config.h b/src/Config.h index 693b00d373..452e652988 100644 --- a/src/Config.h +++ b/src/Config.h @@ -47,6 +47,7 @@ public: boost::filesystem::path CONFIG_FILE; boost::filesystem::path CONFIG_DIR; boost::filesystem::path DATA_DIR; + boost::filesystem::path DEBUG_LOGFILE; boost::filesystem::path UNL_DEFAULT; std::string VALIDATORS_SITE; // Where to find validators.txt on the Internet. diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 105f251bac..81e610c33d 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -108,7 +108,7 @@ Ledger::Ledger(const std::string& rawLedger) : mCloseTime(0), void Ledger::updateHash() { - if(!mImmutable) + if (!mImmutable) { if (mTransactionMap) mTransHash = mTransactionMap->getHash(); else mTransHash.zero(); @@ -235,7 +235,6 @@ uint256 Ledger::getHash() void Ledger::saveAcceptedLedger(Ledger::pointer ledger) { - std::string sql="INSERT INTO Ledgers " "(LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,AccountSetHash,TransSetHash) VALUES ('"; sql.append(ledger->getHash().GetHex()); @@ -328,10 +327,9 @@ Ledger::pointer Ledger::getSQL(const std::string& sql) uint32 ledgerSeq; std::string hash; - if(1) { - ScopedLock sl(theApp->getLedgerDB()->getDBLock()); Database *db = theApp->getLedgerDB()->getDB(); + ScopedLock sl(theApp->getLedgerDB()->getDBLock()); if (!db->executeSQL(sql) || !db->startIterRows()) return Ledger::pointer(); @@ -350,7 +348,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql) db->endIterRows(); } - Ledger::pointer ret=boost::make_shared(prevHash, transHash, accountHash, totCoins, closingTime, ledgerSeq); + Ledger::pointer ret = + boost::make_shared(prevHash, transHash, accountHash, totCoins, closingTime, ledgerSeq); if (ret->getHash() != ledgerHash) { assert(false); diff --git a/src/Ledger.h b/src/Ledger.h index cb9c4cfd15..64ae24a6d5 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -96,7 +96,7 @@ public: void updateHash(); void setClosed() { mClosed = true; } void setAccepted() { mAccepted = true; } - void setImmutable() { mImmutable = true; } + void setImmutable() { updateHash(); mImmutable = true; } bool isClosed() { return mClosed; } bool isAccepted() { return mAccepted; } diff --git a/src/Log.cpp b/src/Log.cpp index ded888a6d6..5efe21a890 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -1,15 +1,15 @@ #include "Log.h" +#include + #include boost::recursive_mutex Log::sLock; -#ifdef DEBUG -LogSeverity Log::sMinSeverity = lsTRACE; -#else -LogSeverity Log::sMinSeverity = lsINFO; -#endif +LogSeverity Log::sMinSeverity = lsWARNING; + +std::ofstream* Log::outStream = NULL; Log::~Log() { @@ -26,9 +26,9 @@ Log::~Log() logMsg += oss.str(); boost::recursive_mutex::scoped_lock sl(sLock); if (mSeverity >= sMinSeverity) - { std::cerr << logMsg << std::endl; - } + if (outStream != NULL) + (*outStream) << logMsg << std::endl; } void Log::setMinSeverity(LogSeverity s) @@ -36,3 +36,20 @@ void Log::setMinSeverity(LogSeverity s) boost::recursive_mutex::scoped_lock sl(sLock); sMinSeverity = s; } + +void Log::setLogFile(boost::filesystem::path path) +{ + std::ofstream* newStream = new std::ofstream(path.c_str(), std::fstream::app); + if (!newStream->good()) + { + delete newStream; + newStream = NULL; + } + + boost::recursive_mutex::scoped_lock sl(sLock); + if (outStream != NULL) + delete outStream; + outStream = newStream; + if (outStream) + Log(lsINFO) << "Starting up"; +} diff --git a/src/Log.h b/src/Log.h index bb5bbc14fb..42c8bb00c9 100644 --- a/src/Log.h +++ b/src/Log.h @@ -4,6 +4,7 @@ #include #include +#include enum LogSeverity { @@ -24,6 +25,7 @@ private: protected: static boost::recursive_mutex sLock; static LogSeverity sMinSeverity; + static std::ofstream* outStream; mutable std::ostringstream oss; LogSeverity mSeverity; @@ -45,6 +47,7 @@ public: } static void setMinSeverity(LogSeverity); + static void setLogFile(boost::filesystem::path); }; #endif diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 5c78116a51..ffe901c1ac 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -474,8 +474,8 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, if (mMode != omFULL) // FIXME: Should we relay? { - Log(lsWARNING) << "Received proposal when not full: " << mMode; - return true; + Log(lsINFO) << "Received proposal when not full: " << mMode; + return false; // FIXME: Need suppression table } if (!mConsensus) {