Tidy up log partition names

This commit is contained in:
Vinnie Falco
2013-06-29 08:26:33 -07:00
parent b17bbb7dad
commit 989549fac5
10 changed files with 88 additions and 77 deletions

View File

@@ -4,4 +4,4 @@
*/
//==============================================================================
SETUP_LOG (TaggedCacheLog)
SETUP_LOGN (TaggedCacheLog,"TaggedCache")

View File

@@ -6,10 +6,9 @@
#define SECTION_DEFAULT_NAME ""
// for logging
struct ParseSectionLog { };
struct ParseSectionLog; // for Log
SETUP_LOG (ParseSectionLog)
SETUP_LOGN (ParseSectionLog,"ParseSection")
Section ParseSection (const std::string& strInput, const bool bTrim)
{

View File

@@ -12,16 +12,16 @@ 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)
LogPartition::LogPartition (char const* partitionName)
: mNextLog (headLog)
, mMinSeverity (lsWARNING)
{
const char* ptr = strrchr (name, '/');
mName = (ptr == NULL) ? name : (ptr + 1);
const char* ptr = strrchr (partitionName, '/');
mName = (ptr == NULL) ? partitionName : (ptr + 1);
size_t p = mName.find (".cpp");
@@ -133,9 +133,9 @@ Log::~Log ()
logMsg += replaceFirstSecretWithAsterisks (oss.str ());
if (logMsg.size () > LOG_MAX_MESSAGE)
if (logMsg.size () > maximumMessageCharacters)
{
logMsg.resize (LOG_MAX_MESSAGE);
logMsg.resize (maximumMessageCharacters);
logMsg += "...";
}

View File

@@ -4,8 +4,8 @@
*/
//==============================================================================
#ifndef RIPPLE_LOG_H
#define RIPPLE_LOG_H
#ifndef RIPPLE_LOG_H_INCLUDED
#define RIPPLE_LOG_H_INCLUDED
enum LogSeverity
{
@@ -20,23 +20,28 @@ enum LogSeverity
//------------------------------------------------------------------------------
// VFALCO TODO make this a nested class in Log
class LogPartition
// VFALCO TODO make this a nested class in Log?
class LogPartition // : public List <LogPartition>::Node
{
protected:
static LogPartition* headLog;
LogPartition* mNextLog;
LogSeverity mMinSeverity;
std::string mName;
public:
LogPartition (const char* name);
LogPartition (const char* partitionName);
/** Retrieve the LogPartition associated with an object.
Each LogPartition is a singleton.
*/
template <class Key>
static LogPartition const& get ()
{
static LogPartition logPartition (getPartitionName <Key> ());
return logPartition;
}
bool doLog (LogSeverity s) const
{
return s >= mMinSeverity;
}
const std::string& getName () const
{
return mName;
@@ -47,33 +52,34 @@ public:
static std::vector< std::pair<std::string, std::string> > getSeverities ();
private:
/** Retrieve file name from a log partition.
/** Retrieve the name for a log partition.
*/
template <class Key>
static char const* getFileName ();
/*
{
static_vfassert (false);
}
*/
static char const* getPartitionName ();
public:
template <class Key>
static LogPartition const& get ()
{
static LogPartition logPartition (getFileName <Key> ());
return logPartition;
}
private:
// VFALCO TODO Use an intrusive linked list
//
static LogPartition* headLog;
LogPartition* mNextLog;
LogSeverity mMinSeverity;
std::string mName;
};
#define SETUP_LOG(k) \
template <> char const* LogPartition::getFileName <k> () { return __FILE__; } \
struct k##Instantiator { k##Instantiator () { LogPartition::get <k> (); } }; \
static k##Instantiator k##Instantiator_instance;
#define SETUP_LOG(Class) \
template <> char const* LogPartition::getPartitionName <Class> () { return #Class; } \
struct Class##Instantiator { Class##Instantiator () { LogPartition::get <Class> (); } }; \
static Class##Instantiator Class##Instantiator_instance;
#define SETUP_LOGN(Class,Name) \
template <> char const* LogPartition::getPartitionName <Class> () { return Name; } \
struct Class##Instantiator { Class##Instantiator () { LogPartition::get <Class> (); } }; \
static Class##Instantiator Class##Instantiator_instance;
//------------------------------------------------------------------------------
class Log
class Log : public Uncopyable
{
public:
explicit Log (LogSeverity s) : mSeverity (s)
@@ -112,9 +118,15 @@ public:
static std::string rotateLog ();
private:
// VFALCO TODO derive from beast::Uncopyable
Log (const Log&); // no implementation
Log& operator= (const Log&); // no implementation
enum
{
/** Maximum line length for log messages.
If the message exceeds this length it will be truncated
with elipses.
*/
maximumMessageCharacters = 12 * 1024
};
// VFALCO TODO looks like there are really TWO classes in here.
// One is a stream target for '<<' operator and the other