add simple log rotating, tentative Ripple pathfinder work

This commit is contained in:
MJK
2012-09-27 13:49:37 -07:00
parent 5a49b696ad
commit 1ffe841be5
7 changed files with 79 additions and 2 deletions

View File

@@ -119,7 +119,7 @@
1
[debug_logfile]
debug.log
log/debug.log
[sntp_servers]
time.windows.com

View File

@@ -10,6 +10,8 @@ boost::recursive_mutex Log::sLock;
LogSeverity Log::sMinSeverity = lsINFO;
std::ofstream* Log::outStream = NULL;
boost::filesystem::path *Log::pathToLog = NULL;
uint32 Log::logRotateCounter = 0;
Log::~Log()
{
@@ -31,6 +33,48 @@ Log::~Log()
(*outStream) << logMsg << std::endl;
}
std::string Log::rotateLog(void)
{
boost::recursive_mutex::scoped_lock sl(sLock);
boost::filesystem::path abs_path;
std::string abs_path_str;
uint32 failsafe = 0;
std::string abs_new_path_str;
do {
std::string s;
std::stringstream out;
failsafe++;
if (failsafe == std::numeric_limits<uint32>::max()) {
return "unable to create new log file; too many log files!";
}
abs_path = boost::filesystem::absolute("");
abs_path /= *pathToLog;
abs_path_str = abs_path.parent_path().string();
out << logRotateCounter;
s = out.str();
abs_new_path_str = abs_path_str + "/" + s + + "_" + pathToLog->filename().string();
logRotateCounter++;
} while (boost::filesystem::exists(boost::filesystem::path(abs_new_path_str)));
outStream->close();
boost::filesystem::rename(abs_path, boost::filesystem::path(abs_new_path_str));
setLogFile(*pathToLog);
return abs_new_path_str;
}
void Log::setMinSeverity(LogSeverity s)
{
boost::recursive_mutex::scoped_lock sl(sLock);
@@ -52,4 +96,6 @@ void Log::setLogFile(boost::filesystem::path path)
outStream = newStream;
if (outStream)
Log(lsINFO) << "Starting up";
pathToLog = new boost::filesystem::path(path);
}

View File

@@ -9,6 +9,9 @@
// Ensure that we don't get value.h without writer.h
#include "../json/json.h"
#include "types.h"
#include <limits>
enum LogSeverity
{
lsTRACE = 0,
@@ -33,6 +36,9 @@ protected:
mutable std::ostringstream oss;
LogSeverity mSeverity;
static boost::filesystem::path *pathToLog;
static uint32 logRotateCounter;
public:
Log(LogSeverity s) : mSeverity(s)
{ ; }
@@ -51,6 +57,7 @@ public:
static void setMinSeverity(LogSeverity);
static void setLogFile(boost::filesystem::path);
static std::string rotateLog(void);
};
#endif

View File

@@ -14,6 +14,11 @@
#include "Log.h"
#include "RippleLines.h"
#include "Pathfinder.h"
#include "Conversion.h"
extern uint160 humanTo160(const std::string& buf);
#include <iostream>
#include <boost/bind.hpp>
@@ -1795,6 +1800,16 @@ Json::Value RPCServer::doSend(const Json::Value& params)
STPathSet spsPaths;
uint160 srcCurrencyID;
bool ret_b;
ret_b = false;
STAmount::currencyFromString(srcCurrencyID, sSrcCurrency);
Pathfinder pf(naSrcAccountID, naDstAccountID, srcCurrencyID, saDstAmount);
ret_b = pf.findPaths(5, 1, spsPaths);
// TODO: Nope; the above can't be right
trans = Transaction::sharedPayment(
naAccountPublic, naAccountPrivate,
naSrcAccountID,
@@ -2518,6 +2533,11 @@ Json::Value RPCServer::doLogin(const Json::Value& params)
}
}
Json::Value RPCServer::doLogRotate(const Json::Value& params)
{
return Log::rotateLog();
}
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
{
Log(lsTRACE) << "RPC:" << command;
@@ -2543,6 +2563,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
{ "data_fetch", &RPCServer::doDataFetch, 1, 1, true },
{ "data_store", &RPCServer::doDataStore, 2, 2, true },
{ "ledger", &RPCServer::doLedger, 0, 2, false, optNetwork },
{ "logrotate", &RPCServer::doLogRotate, 0, 0, true, optCurrent },
{ "nickname_info", &RPCServer::doNicknameInfo, 1, 1, false, optCurrent },
{ "nickname_set", &RPCServer::doNicknameSet, 2, 3, false, optCurrent },
{ "offer_create", &RPCServer::doOfferCreate, 9, 10, false, optCurrent },

View File

@@ -141,6 +141,7 @@ private:
Json::Value doDataFetch(const Json::Value& params);
Json::Value doDataStore(const Json::Value& params);
Json::Value doLedger(const Json::Value& params);
Json::Value doLogRotate(const Json::Value& params);
Json::Value doNicknameInfo(const Json::Value& params);
Json::Value doNicknameSet(const Json::Value& params);
Json::Value doOfferCreate(const Json::Value& params);
@@ -184,6 +185,7 @@ private:
Json::Value doLogin(const Json::Value& params);
public:
static pointer create(boost::asio::io_service& io_service, NetworkOPs* mNetOps)
{

View File

@@ -51,6 +51,7 @@ void printHelp(const po::options_description& desc)
cout << " data_fetch <key>" << endl;
cout << " data_store <key> <value>" << endl;
cout << " ledger [<id>|current|lastclosed] [full]" << endl;
cout << " logrotate " << endl;
cout << " nickname_info <nickname>" << endl;
cout << " nickname_set <seed> <paying_account> <nickname> [<offer_minimum>] [<authorization>]" << endl;
cout << " offer_create <seed> <paying_account> <taker_pays_amount> <taker_pays_currency> <taker_pays_issuer> <takers_gets_amount> <takers_gets_currency> <takers_gets_issuer> <expires> [passive]" << endl;