Move Log to ripple_basics and split websocket logging to ripple_net

This commit is contained in:
Vinnie Falco
2013-05-25 14:53:31 -07:00
parent 1f940b60c4
commit d762abfc85
49 changed files with 133 additions and 160 deletions

View File

@@ -10,7 +10,6 @@
#include <boost/test/unit_test.hpp>
#include "Config.h"
#include "Log.h"
#include "SerializedTypes.h"
#include "utils.h"

View File

@@ -2,7 +2,6 @@
#include <boost/test/unit_test.hpp>
#include "SerializedTypes.h"
#include "Log.h"
#if (ULONG_MAX > UINT_MAX)
#define BN_add_word64(bn, word) BN_add_word(bn, word)

View File

@@ -14,7 +14,6 @@
#include "key.h"
#include "utils.h"
#include "TaggedCache.h"
#include "Log.h"
#include "../database/SqliteDatabase.h"

View File

@@ -12,7 +12,6 @@
#include <boost/asio/ssl.hpp>
#include <boost/asio/read_until.hpp>
#include "Log.h"
extern LogPartition AutoSocketPartition;
// Socket wrapper that supports both SSL and non-SSL connections.

View File

@@ -22,7 +22,6 @@
#include "Application.h"
#include "RPC.h"
#include "Log.h"
#include "RPCErr.h"
#include "Config.h"
#include "BitcoinUtil.h"

View File

@@ -13,7 +13,6 @@
#include "PeerDoor.h"
#include "Application.h"
#include "utils.h"
#include "Log.h"
// How often to enforce policies.
#define POLICY_INTERVAL_SECONDS 5

View File

@@ -12,7 +12,6 @@
#include <boost/test/unit_test.hpp>
#include "Serializer.h"
#include "Log.h"
// <-- seed
uint128 CKey::PassPhraseToKey(const std::string& passPhrase)

View File

@@ -4,8 +4,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include "Log.h"
SETUP_LOG (HTTPRequest)
// Logic to handle incoming HTTP reqests

View File

@@ -12,7 +12,6 @@
#include "Serializer.h"
#include "Application.h"
#include "Log.h"
SETUP_LOG (HashedObject)

View File

@@ -12,7 +12,6 @@
#include <boost/system/error_code.hpp>
#include "Config.h"
#include "Log.h"
#define CLIENT_MAX_HEADER (32*1024)

View File

@@ -4,7 +4,6 @@
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include "Log.h"
#include "Config.h"
#include "Application.h"

View File

@@ -4,7 +4,6 @@
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "Log.h"
#include "Config.h"
#include "Application.h"

View File

@@ -1,5 +1,4 @@
#include "LoadMonitor.h"
#include "Log.h"
SETUP_LOG (LoadMonitor)

View File

@@ -1,248 +0,0 @@
#include "Log.h"
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include "../websocketpp/src/logger/logger.hpp"
boost::recursive_mutex Log::sLock;
LogSeverity Log::sMinSeverity = lsINFO;
std::ofstream* Log::outStream = NULL;
boost::filesystem::path *Log::pathToLog = NULL;
uint32 Log::logRotateCounter = 0;
#ifndef LOG_MAX_MESSAGE
#define LOG_MAX_MESSAGE (12 * 1024)
#endif
LogPartition* LogPartition::headLog = NULL;
LogPartition::LogPartition(const char *name) : mNextLog(headLog), mMinSeverity(lsWARNING)
{
const char *ptr = strrchr(name, '/');
mName = (ptr == NULL) ? name : (ptr + 1);
size_t p = mName.find(".cpp");
if (p != std::string::npos)
mName.erase(mName.begin() + p, mName.end());
headLog = this;
}
std::vector< std::pair<std::string, std::string> > LogPartition::getSeverities()
{
std::vector< std::pair<std::string, std::string> > sevs;
for (LogPartition *l = headLog; l != NULL; l = l->mNextLog)
sevs.push_back(std::make_pair(l->mName, Log::severityToString(l->mMinSeverity)));
return sevs;
}
Log::~Log()
{
std::string logMsg = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time());
if (!mPartitionName.empty())
logMsg += " " + mPartitionName + ":";
else
logMsg += " ";
switch (mSeverity)
{
case lsTRACE: logMsg += "TRC "; break;
case lsDEBUG: logMsg += "DBG "; break;
case lsINFO: logMsg += "NFO "; break;
case lsWARNING: logMsg += "WRN "; break;
case lsERROR: logMsg += "ERR "; break;
case lsFATAL: logMsg += "FTL "; break;
case lsINVALID: assert(false); return;
}
logMsg += oss.str();
if (logMsg.size() > LOG_MAX_MESSAGE)
{
logMsg.resize(LOG_MAX_MESSAGE);
logMsg += "...";
}
boost::recursive_mutex::scoped_lock sl(sLock);
if (mSeverity >= sMinSeverity)
std::cerr << logMsg << std::endl;
if (outStream != NULL)
(*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();
try
{
boost::filesystem::rename(abs_path, boost::filesystem::path(abs_new_path_str));
}
catch (...)
{
// unable to rename existing log file
}
setLogFile(*pathToLog);
return abs_new_path_str;
}
void Log::setMinSeverity(LogSeverity s, bool all)
{
boost::recursive_mutex::scoped_lock sl(sLock);
sMinSeverity = s;
if (all)
LogPartition::setSeverity(s);
}
LogSeverity Log::getMinSeverity()
{
boost::recursive_mutex::scoped_lock sl(sLock);
return sMinSeverity;
}
std::string Log::severityToString(LogSeverity s)
{
switch (s)
{
case lsTRACE: return "Trace";
case lsDEBUG: return "Debug";
case lsINFO: return "Info";
case lsWARNING: return "Warning";
case lsERROR: return "Error";
case lsFATAL: return "Fatal";
default: assert(false); return "Unknown";
}
}
LogSeverity Log::stringToSeverity(const std::string& s)
{
if (boost::iequals(s, "trace"))
return lsTRACE;
if (boost::iequals(s, "debug"))
return lsDEBUG;
if (boost::iequals(s, "info") || boost::iequals(s, "information"))
return lsINFO;
if (boost::iequals(s, "warn") || boost::iequals(s, "warning") || boost::iequals(s, "warnings"))
return lsWARNING;
if (boost::iequals(s, "error") || boost::iequals(s, "errors"))
return lsERROR;
if (boost::iequals(s, "fatal") || boost::iequals(s, "fatals"))
return lsFATAL;
return lsINVALID;
}
void Log::setLogFile(boost::filesystem::path const& path)
{
std::ofstream* newStream = new std::ofstream(path.c_str(), std::fstream::app);
if (!newStream->good())
{
Log(lsFATAL) << "Unable to open logfile " << path;
delete newStream;
newStream = NULL;
}
boost::recursive_mutex::scoped_lock sl(sLock);
if (outStream != NULL)
delete outStream;
outStream = newStream;
if (pathToLog != NULL)
delete pathToLog;
pathToLog = new boost::filesystem::path(path);
}
bool LogPartition::setSeverity(const std::string& partition, LogSeverity severity)
{
for (LogPartition *p = headLog; p != NULL; p = p->mNextLog)
if (boost::iequals(p->mName, partition))
{
p->mMinSeverity = severity;
return true;
}
return false;
}
void LogPartition::setSeverity(LogSeverity severity)
{
for (LogPartition *p = headLog; p != NULL; p = p->mNextLog)
p->mMinSeverity = severity;
}
namespace websocketpp
{
namespace log
{
LogPartition websocketPartition("WebSocket");
void websocketLog(websocketpp::log::alevel::value v, const std::string& entry)
{
if ((v == websocketpp::log::alevel::DEVEL) || (v == websocketpp::log::alevel::DEBUG_CLOSE))
{
if (websocketPartition.doLog(lsTRACE))
Log(lsDEBUG, websocketPartition) << entry;
}
else if (websocketPartition.doLog(lsDEBUG))
Log(lsDEBUG, websocketPartition) << entry;
}
void websocketLog(websocketpp::log::elevel::value v, const std::string& entry)
{
LogSeverity s = lsDEBUG;
if ((v & websocketpp::log::elevel::INFO) != 0)
s = lsINFO;
else if ((v & websocketpp::log::elevel::FATAL) != 0)
s = lsFATAL;
else if ((v & websocketpp::log::elevel::RERROR) != 0)
s = lsERROR;
else if ((v & websocketpp::log::elevel::WARN) != 0)
s = lsWARNING;
if (websocketPartition.doLog(s))
Log(s, websocketPartition) << entry;
}
}
}
// vim:ts=4

View File

@@ -1,138 +0,0 @@
#ifndef __LOG__
#define __LOG__
#include <sstream>
#include <string>
#include <limits>
#include <boost/thread/recursive_mutex.hpp>
// VFALCO: TODO, fix this for Linux builds
// Forward declaration
/*
namespace boost {
namespace filesystem {
class path;
}
}
*/
#include <boost/filesystem.hpp> // unfortunately needed to compile
enum LogSeverity
{
lsINVALID = -1, // used to indicate an invalid severity
lsTRACE = 0, // Very low-level progress information, details inside an operation
lsDEBUG = 1, // Function-level progress information, operations
lsINFO = 2, // Server-level progress information, major operations
lsWARNING = 3, // Conditions that warrant human attention, may indicate a problem
lsERROR = 4, // A condition that indicates a problem
lsFATAL = 5 // A severe condition that indicates a server problem
};
//------------------------------------------------------------------------------
// VFALCO: TODO, make this a nested class in Log
class LogPartition
{
protected:
static LogPartition* headLog;
LogPartition* mNextLog;
LogSeverity mMinSeverity;
std::string mName;
public:
LogPartition(const char *name);
bool doLog(LogSeverity s) const { return s >= mMinSeverity; }
const std::string& getName() const { return mName; }
static bool setSeverity(const std::string& partition, LogSeverity severity);
static void setSeverity(LogSeverity severity);
static std::vector< std::pair<std::string, std::string> > getSeverities();
private:
/** Retrieve file name from a log partition.
*/
template <class Key>
inline static char const* getFileName ();
/*
{
static_vfassert (false);
}
*/
public:
template <class Key>
inline static LogPartition const& get ()
{
static LogPartition logPartition (getFileName <Key> ());
return logPartition;
}
};
#define SETUP_LOG(k) template <> char const* LogPartition::getFileName <k> () { return __FILE__; }
//------------------------------------------------------------------------------
class Log
{
private:
Log(const Log&); // no implementation
Log& operator=(const Log&); // no implementation
protected:
static boost::recursive_mutex sLock;
static LogSeverity sMinSeverity;
static std::ofstream* outStream;
mutable std::ostringstream oss;
LogSeverity mSeverity;
std::string mPartitionName;
static boost::filesystem::path *pathToLog;
static uint32 logRotateCounter;
public:
Log(LogSeverity s) : mSeverity(s)
{ ; }
Log(LogSeverity s, const LogPartition& p) : mSeverity(s), mPartitionName(p.getName())
{ ; }
~Log();
template<typename T> std::ostream& operator<<(const T& t) const
{
return oss << t;
}
std::ostringstream& ref(void) const
{
return oss;
}
static std::string severityToString(LogSeverity);
static LogSeverity stringToSeverity(const std::string&);
static LogSeverity getMinSeverity();
static void setMinSeverity(LogSeverity, bool all);
static void setLogFile(boost::filesystem::path const&);
static std::string rotateLog(void);
};
// Manually test for whether we should log
//
#define ShouldLog(s, k) (LogPartition::get <k> ().doLog (s))
// Write to the log at the given severity level
//
#define WriteLog(s, k) if (!ShouldLog (s, k)) do {} while (0); else Log (s, LogPartition::get <k> ())
// Write to the log conditionally
//
#define CondLog(c, s, k) if (!ShouldLog (s, k) || !(c)) do {} while(0); else Log(s, LogPartition::get <k> ())
#endif
// vim:ts=4

View File

@@ -9,7 +9,6 @@
#include "HashPrefixes.h"
#include "LedgerConsensus.h"
#include "LedgerTiming.h"
#include "Log.h"
#include "RippleAddress.h"
SETUP_LOG (NetworkOPs)

View File

@@ -1,5 +1,4 @@
#include "ParseSection.h"
#include "Log.h"
#include "utils.h"
#include <iostream>

View File

@@ -6,7 +6,6 @@
#include <boost/foreach.hpp>
#include "Application.h"
#include "Log.h"
SETUP_LOG (Pathfinder)

View File

@@ -11,7 +11,6 @@
#include "Application.h"
#include "SerializedTransaction.h"
#include "utils.h"
#include "Log.h"
SETUP_LOG (Peer)

View File

@@ -9,7 +9,6 @@
#include "Application.h"
#include "Config.h"
#include "utils.h"
#include "Log.h"
SETUP_LOG (PeerDoor)

View File

@@ -10,7 +10,6 @@
#include <openssl/rand.h>
#include "Serializer.h"
#include "Log.h"
SETUP_LOG (ProofOfWork)

View File

@@ -1,7 +1,6 @@
#include "RPCDoor.h"
#include "Application.h"
#include "Config.h"
#include "Log.h"
#include <boost/bind.hpp>
#include <iostream>

View File

@@ -1,6 +1,4 @@
#include "Log.h"
#include "RPCErr.h"
#include "utils.h"

View File

@@ -9,7 +9,6 @@
#include <boost/pointer_cast.hpp>
#include "Pathfinder.h"
#include "Log.h"
#include "RPCHandler.h"
#include "RPCSub.h"
#include "Application.h"

View File

@@ -1,5 +1,4 @@
#include "RPCServer.h"
#include "Log.h"
#include "HttpsClient.h"
#include "RPC.h"

View File

@@ -4,8 +4,6 @@
#include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
#include "Log.h"
SETUP_LOG (RangeSet)
inline uint32 min(uint32 x, uint32 y) { return (x < y) ? x : y; }

View File

@@ -17,7 +17,6 @@
#include "BitcoinUtil.h"
#include "rfc1751.h"
#include "utils.h"
#include "Log.h"
#include "Serializer.h"
#include "Application.h"

View File

@@ -11,7 +11,6 @@
#include "Serializer.h"
#include "BitcoinUtil.h"
#include "Log.h"
#include "SHAMap.h"
#include "Application.h"

View File

@@ -13,7 +13,6 @@
#include "Serializer.h"
#include "BitcoinUtil.h"
#include "Log.h"
#include "HashPrefixes.h"
SETUP_LOG (SHAMapNode)

View File

@@ -9,8 +9,6 @@
#include <openssl/rand.h>
#include "Log.h"
static const uint256 uZero;
KeyCache <uint256, KeyCacheUptimeTimer> SHAMap::fullBelowCache("fullBelowCache", 65536, 240);

View File

@@ -8,7 +8,6 @@
#include "utils.h"
#include "Config.h"
#include "Log.h"
SETUP_LOG (SNTPClient)

View File

@@ -8,7 +8,6 @@
#include "Serializer.h"
#include "FieldNames.h"
#include "InstanceCounter.h"
#include "Log.h"
// CAUTION: Do not create a vector (or similar container) of any object derived from
// SerializedType. Use Boost ptr_* containers. The copy assignment operator of

View File

@@ -9,7 +9,6 @@
#include <boost/ref.hpp>
#include <boost/make_shared.hpp>
#include "Log.h"
extern LogPartition TaggedCachePartition;
extern int upTime();

View File

@@ -17,7 +17,6 @@
#include "Application.h"
#include "HttpsClient.h"
#include "Log.h"
#include "ParseSection.h"
#include "Serializer.h"
#include "utils.h"

View File

@@ -5,7 +5,6 @@
#include "Application.h"
#include "LedgerTiming.h"
#include "Log.h"
SETUP_LOG (ValidationCollection)

View File

@@ -12,7 +12,6 @@
#include "NetworkOPs.h"
#include "CallRPC.h"
#include "InstanceCounter.h"
#include "Log.h"
#include "LoadManager.h"
#include "RPCErr.h"

View File

@@ -1,5 +1,4 @@
#include "Log.h"
//#define WSDOOR_CPP
//#include "../websocketpp/src/sockets/autotls.hpp"

View File

@@ -3,7 +3,6 @@
#include "Application.h"
#include "Config.h"
#include "Log.h"
extern void initSSLContext(boost::asio::ssl::context& context,
std::string key_file, std::string cert_file, std::string chain_file);

View File

@@ -9,7 +9,6 @@
#include "Application.h"
#include "CallRPC.h"
#include "Config.h"
#include "Log.h"
#include "RPCHandler.h"
#include "utils.h"

View File

@@ -11,7 +11,6 @@
#include "RPC.h"
#include "BitcoinUtil.h"
#include "Config.h"
#include "Log.h"
#include "Version.h"
// Used for logging