- logging improved
This commit is contained in:
@@ -126,7 +126,7 @@ bool AuthTransaction::processData(StunMessage& msg, NetworkAddress& address)
|
||||
mState = Transaction::Failed;
|
||||
processError();
|
||||
|
||||
ICELogCritical(<<"Stack ID " << mStackID << ". Got error code " << mErrorCode << " for STUN transaction. Error message: " << ec.errorPhrase());
|
||||
ICELogError(<<"Stack ID " << mStackID << ". Got error code " << mErrorCode << " for STUN transaction. Error message: " << ec.errorPhrase());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -135,7 +135,7 @@ bool AuthTransaction::processData(StunMessage& msg, NetworkAddress& address)
|
||||
mErrorCode = 0;
|
||||
mState = Transaction::Failed;
|
||||
processError();
|
||||
ICELogCritical(<<"Stack ID " << mStackID << ". Got ErrorClass response.");
|
||||
ICELogError(<<"Stack ID " << mStackID << ". Got ErrorClass response.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -347,7 +347,7 @@ bool ServerBinding::processData(StunMessage& msg, NetworkAddress& address)
|
||||
|
||||
if (!msg.hasAttribute(StunAttribute::Username) || !msg.hasAttribute(StunAttribute::MessageIntegrity))
|
||||
{
|
||||
ICELogCritical(<< "There is no Username or MessageIntegrity attributes in Binding required. Error 400 will be generated.");
|
||||
ICELogError(<< "There is no Username or MessageIntegrity attributes in Binding required. Error 400 will be generated.");
|
||||
// Send 400 error
|
||||
mGenerate400 = true;
|
||||
|
||||
@@ -423,7 +423,7 @@ ByteBuffer* ServerBinding::generateData(bool force)
|
||||
// Do not create username attribute here - response does not need it
|
||||
// msg.usernameAttr().setValue(mUsername);
|
||||
|
||||
//ICELogCritical(<< "Using password " << mPassword);
|
||||
//ICELogMedia(<< "Using password " << mPassword);
|
||||
|
||||
// Add message integrity attribute
|
||||
msg.setAttribute(new MessageIntegrity());
|
||||
|
||||
@@ -62,7 +62,7 @@ const char* Candidate::type()
|
||||
return "prflx";
|
||||
|
||||
default:
|
||||
ICELogCritical(<< "Bad candidate type, reverted to Host.");
|
||||
ICELogError(<< "Bad candidate type, reverted to Host.");
|
||||
return "host";
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ Candidate::Type Candidate::typeFromString(const char* candtype)
|
||||
return Candidate::ServerRelayed;
|
||||
else
|
||||
{
|
||||
ICELogCritical(<< "Bad candidate type in parser. Reverted to Host");
|
||||
ICELogError(<< "Bad candidate type in parser. Reverted to Host");
|
||||
return Candidate::Host;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ bool Candidate::equal(Candidate& cand1, Candidate& cand2)
|
||||
|
||||
}
|
||||
|
||||
ICELogCritical(<< "Bad candidate type, comparing as Host");
|
||||
ICELogError(<< "Bad candidate type, comparing as Host");
|
||||
return cand1.mLocalAddr == cand2.mLocalAddr;
|
||||
}
|
||||
|
||||
@@ -185,4 +185,4 @@ void Candidate::dump(std::ostream& output)
|
||||
int Candidate::component()
|
||||
{
|
||||
return mComponentId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,49 @@
|
||||
|
||||
using namespace ice;
|
||||
|
||||
|
||||
LogLevel LogLevelHelper::parse(const std::string& t)
|
||||
{
|
||||
if (t == "none")
|
||||
return LL_NONE;
|
||||
else
|
||||
if (t == "debug")
|
||||
return LL_DEBUG;
|
||||
else
|
||||
if (t == "critical")
|
||||
return LL_CRITICAL;
|
||||
else
|
||||
if (t == "info")
|
||||
return LL_INFO;
|
||||
else
|
||||
if (t == "media")
|
||||
return LL_MEDIA;
|
||||
else
|
||||
if (t == "critical")
|
||||
return LL_CRITICAL;
|
||||
else
|
||||
if (t == "special")
|
||||
return LL_SPECIAL;
|
||||
|
||||
throw std::runtime_error("Bad log param string value.");
|
||||
}
|
||||
|
||||
std::string LogLevelHelper::toString(LogLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case LL_NONE: return "none";
|
||||
case LL_CRITICAL: return "critical";
|
||||
case LL_DEBUG: return "debug";
|
||||
case LL_ERROR: return "error";
|
||||
case LL_INFO: return "info";
|
||||
case LL_MEDIA: return "media";
|
||||
case LL_SPECIAL: return "special";
|
||||
}
|
||||
|
||||
throw std::runtime_error("Bad log param value.");
|
||||
}
|
||||
|
||||
ice::Logger ice::GLogger;
|
||||
const char* ice::Logger::TabPrefix = " ";
|
||||
|
||||
|
||||
@@ -20,72 +20,83 @@
|
||||
|
||||
namespace ice
|
||||
{
|
||||
// Defines log levels
|
||||
enum LogLevel
|
||||
{
|
||||
LL_NONE = -1,
|
||||
LL_CRITICAL = 0,
|
||||
LL_INFO = 1,
|
||||
LL_DEBUG = 2,
|
||||
LL_MEDIA = 3
|
||||
};
|
||||
|
||||
class LogHandler
|
||||
{
|
||||
public:
|
||||
// Defines log levels
|
||||
enum LogLevel
|
||||
{
|
||||
LL_NONE = -1000,
|
||||
LL_SPECIAL = 0,
|
||||
LL_CRITICAL = 1,
|
||||
LL_ERROR = 2,
|
||||
LL_INFO = 3,
|
||||
LL_DEBUG = 4,
|
||||
LL_MEDIA = 5
|
||||
};
|
||||
|
||||
// Helper function to convert log level text parameter to enum value
|
||||
class LogLevelHelper
|
||||
{
|
||||
public:
|
||||
static LogLevel parse(const std::string& t);
|
||||
static std::string toString(LogLevel level);
|
||||
};
|
||||
|
||||
class LogHandler
|
||||
{
|
||||
public:
|
||||
virtual void onIceLog(LogLevel level, const std::string& filename, int line, const std::string& subsystem, const std::string& msg) = 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
class LogGuard
|
||||
{
|
||||
public:
|
||||
class LogGuard
|
||||
{
|
||||
public:
|
||||
LogGuard() { ::InitializeCriticalSection(&mCS); }
|
||||
~LogGuard() { ::DeleteCriticalSection(&mCS); }
|
||||
void Lock() { ::EnterCriticalSection(&mCS); }
|
||||
void Unlock() { ::LeaveCriticalSection(&mCS); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
CRITICAL_SECTION mCS;
|
||||
};
|
||||
};
|
||||
|
||||
class LogLock
|
||||
{
|
||||
public:
|
||||
class LogLock
|
||||
{
|
||||
public:
|
||||
LogLock(LogGuard& g) :mGuard(g) { mGuard.Lock(); }
|
||||
~LogLock() { mGuard.Unlock(); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
LogGuard& mGuard;
|
||||
};
|
||||
};
|
||||
#else
|
||||
class LogGuard
|
||||
{
|
||||
public:
|
||||
class LogGuard
|
||||
{
|
||||
public:
|
||||
LogGuard() { ::pthread_mutex_init(&mMutex, NULL); }
|
||||
~LogGuard() { ::pthread_mutex_destroy(&mMutex); }
|
||||
void Lock() { ::pthread_mutex_lock(&mMutex); }
|
||||
void Unlock() { ::pthread_mutex_unlock(&mMutex); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
pthread_mutex_t mMutex;
|
||||
};
|
||||
};
|
||||
|
||||
class LogLock
|
||||
{
|
||||
public:
|
||||
class LogLock
|
||||
{
|
||||
public:
|
||||
LogLock(LogGuard& g) :mGuard(g) { mGuard.Lock(); }
|
||||
~LogLock() { mGuard.Unlock(); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
LogGuard& mGuard;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
static const char* TabPrefix;
|
||||
|
||||
Logger();
|
||||
@@ -113,7 +124,7 @@ namespace ice
|
||||
Logger& operator << (const unsigned int data);
|
||||
Logger& operator << (const uint64_t data);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
LogGuard mGuard;
|
||||
FILE* mFile;
|
||||
std::string mLogPath;
|
||||
@@ -127,40 +138,46 @@ namespace ice
|
||||
std::string mFilename;
|
||||
int mLine;
|
||||
std::string mSubsystem;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
extern Logger GLogger;
|
||||
|
||||
|
||||
#define ICELog(level_, subsystem_, args_)\
|
||||
{do\
|
||||
{\
|
||||
if (GLogger.level() >= level_)\
|
||||
{\
|
||||
LogLock l(GLogger.mutex());\
|
||||
GLogger.beginLine(level_, __FILE__, __LINE__, subsystem_);\
|
||||
GLogger args_;\
|
||||
GLogger.endLine();\
|
||||
}\
|
||||
} while (false);}
|
||||
{do\
|
||||
{\
|
||||
if (GLogger.level() >= level_)\
|
||||
{\
|
||||
LogLock l(GLogger.mutex());\
|
||||
GLogger.beginLine(level_, __FILE__, __LINE__, subsystem_);\
|
||||
GLogger args_;\
|
||||
GLogger.endLine();\
|
||||
}\
|
||||
} while (false);}
|
||||
|
||||
#define ICELogCritical(args_) ICELog(LL_CRITICAL, LOG_SUBSYSTEM, args_)
|
||||
#define ICELogInfo(args_) ICELog(LL_INFO, LOG_SUBSYSTEM, args_)
|
||||
#define ICELogDebug(args_) ICELog(LL_DEBUG, LOG_SUBSYSTEM, args_)
|
||||
#define ICELogMedia(args_) ICELog(LL_MEDIA, LOG_SUBSYSTEM, args_)
|
||||
#define ICELogError(args_) ICELog(LL_ERROR, LOG_SUBSYSTEM, args_)
|
||||
#define ICELogSpecial(args_) ICELog(LL_SPECIAL, LOG_SUBSYSTEM, args_)
|
||||
|
||||
#define ICELogCritical2(args_) ICELog(LogLevel_Critical, LogSubsystem.c_str(), args_)
|
||||
#define ICELogInfo2(args_) ICELog(LogLevel_Info, LogSubsystem.c_str(), args_)
|
||||
#define ICELogDebug2(args_) ICELog(LogLevel_Debug, LogSubsystem.c_str(), args_)
|
||||
#define ICELogMedia2(args_) ICELog(LogLevel_Media, LogSubsystem.c_str(), args_)
|
||||
#define ICELogError2(args_) ICELog(LogLevel_Error, LogSubsystem.c_str(), args_)
|
||||
#define ICELogSpecial2(args_) ICELog(LogLevel_Special, LogSubsystem.c_str(), args_)
|
||||
|
||||
#define DEFINE_LOGGING(subsystem) \
|
||||
static std::string LogSubsystem = subsystem; \
|
||||
static ice::LogLevel LogLevel_Critical = LL_CRITICAL; \
|
||||
static ice::LogLevel LogLevel_Info = LL_INFO; \
|
||||
static ice::LogLevel LogLevel_Debug = LL_DEBUG; \
|
||||
static ice::LogLevel LogLevel_Media = LL_MEDIA
|
||||
static ice::LogLevel LogLevel_Media = LL_MEDIA; \
|
||||
static ice::LogLevel LogLevel_Error = LL_ERROR; \
|
||||
static ice::LogLevel LogLevel_Special = LL_SPECIAL
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -399,7 +399,7 @@ NetworkHelper& NetworkHelper::instance()
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ICELogCritical(<< "Failed to create NetworkHelper instance");
|
||||
ICELogError(<< "Failed to create NetworkHelper instance");
|
||||
}
|
||||
mGuard.unlock();
|
||||
|
||||
|
||||
@@ -201,10 +201,10 @@ void ClientRefresh::processError()
|
||||
{
|
||||
if (mStream->mTurnAllocated > 0)
|
||||
mStream->mTurnAllocated--;
|
||||
ICELogCritical(<< "TURN allocation is not deleted due to error " << errorCode() << " " << errorResponse());
|
||||
ICELogError(<< "TURN allocation is not deleted due to error " << errorCode() << " " << errorResponse());
|
||||
}
|
||||
else
|
||||
ICELogDebug(<< "ClientRefresh failed due to error " << errorCode() << " " << errorResponse());
|
||||
ICELogError(<< "ClientRefresh failed due to error " << errorCode() << " " << errorResponse());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ int Session::addComponent(int streamID, void* tag, unsigned short port4, unsigne
|
||||
|
||||
if (mStreamMap.find(streamID) == mStreamMap.end())
|
||||
{
|
||||
ICELogCritical(<< "Cannot find stream " << streamID << " to add new component.");
|
||||
ICELogError(<< "Cannot find stream " << streamID << " to add new component.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user