mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Initial support for log partition.
This commit is contained in:
19
src/Log.cpp
19
src/Log.cpp
@@ -13,6 +13,8 @@ std::ofstream* Log::outStream = NULL;
|
|||||||
boost::filesystem::path *Log::pathToLog = NULL;
|
boost::filesystem::path *Log::pathToLog = NULL;
|
||||||
uint32 Log::logRotateCounter = 0;
|
uint32 Log::logRotateCounter = 0;
|
||||||
|
|
||||||
|
LogPartition* LogPartition::headLog = NULL;
|
||||||
|
|
||||||
Log::~Log()
|
Log::~Log()
|
||||||
{
|
{
|
||||||
std::string logMsg = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time());
|
std::string logMsg = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time());
|
||||||
@@ -79,6 +81,7 @@ void Log::setMinSeverity(LogSeverity s)
|
|||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock sl(sLock);
|
boost::recursive_mutex::scoped_lock sl(sLock);
|
||||||
sMinSeverity = s;
|
sMinSeverity = s;
|
||||||
|
LogPartition::setSeverity(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::setLogFile(boost::filesystem::path path)
|
void Log::setLogFile(boost::filesystem::path path)
|
||||||
@@ -99,3 +102,19 @@ void Log::setLogFile(boost::filesystem::path path)
|
|||||||
|
|
||||||
pathToLog = new boost::filesystem::path(path);
|
pathToLog = new boost::filesystem::path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogPartition::setSeverity(const char *partition, LogSeverity severity)
|
||||||
|
{
|
||||||
|
for (LogPartition *p = headLog; p != NULL; p = p->mNextLog)
|
||||||
|
if (p->mName == partition)
|
||||||
|
{
|
||||||
|
p->mMinSeverity = severity;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogPartition::setSeverity(LogSeverity severity)
|
||||||
|
{
|
||||||
|
for (LogPartition *p = headLog; p != NULL; p = p->mNextLog)
|
||||||
|
p->mMinSeverity = severity;
|
||||||
|
}
|
||||||
|
|||||||
32
src/Log.h
32
src/Log.h
@@ -2,6 +2,8 @@
|
|||||||
#define __LOG__
|
#define __LOG__
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
@@ -10,7 +12,9 @@
|
|||||||
#include "../json/json.h"
|
#include "../json/json.h"
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <limits>
|
|
||||||
|
#define SETUP_LOG() static LogPartition logPartition(__FILE__)
|
||||||
|
#define cLog(x) if (logPartition.doLog(x)) Log(x)
|
||||||
|
|
||||||
enum LogSeverity
|
enum LogSeverity
|
||||||
{
|
{
|
||||||
@@ -22,6 +26,32 @@ enum LogSeverity
|
|||||||
lsFATAL = 5
|
lsFATAL = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LogPartition
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
static LogPartition* headLog;
|
||||||
|
|
||||||
|
LogPartition* mNextLog;
|
||||||
|
LogSeverity mMinSeverity;
|
||||||
|
std::string mName;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LogPartition(const char *name) : mNextLog(headLog), mMinSeverity(lsWARNING)
|
||||||
|
{
|
||||||
|
const char *ptr = strrchr(name, '/');
|
||||||
|
mName = (ptr == NULL) ? name : ptr;
|
||||||
|
headLog = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool doLog(enum LogSeverity s)
|
||||||
|
{
|
||||||
|
return s >= mMinSeverity;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setSeverity(const char *partition, LogSeverity severity);
|
||||||
|
static void setSeverity(LogSeverity severity);
|
||||||
|
};
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user