- minor fixes
This commit is contained in:
parent
8fe79459d5
commit
8cd493018e
|
|
@ -663,7 +663,7 @@ bool UserAgent::operator()(resip::Log::Level level, const resip::Subsystem& subs
|
||||||
|
|
||||||
ss << "File " << StringHelper::extractFilename(filename).c_str() << ", line " << line << ": " << message.c_str();
|
ss << "File " << StringHelper::extractFilename(filename).c_str() << ", line " << line << ": " << message.c_str();
|
||||||
if (level <= resip::Log::Crit)
|
if (level <= resip::Log::Crit)
|
||||||
ICELogCritical(<< ss.str());
|
ICELogCritical(<< ss.str())
|
||||||
else
|
else
|
||||||
if (level <= resip::Log::Warning)
|
if (level <= resip::Log::Warning)
|
||||||
ICELogError(<< ss.str().c_str())
|
ICELogError(<< ss.str().c_str())
|
||||||
|
|
|
||||||
|
|
@ -20,25 +20,25 @@ using namespace ice;
|
||||||
LogLevel LogLevelHelper::parse(const std::string& t)
|
LogLevel LogLevelHelper::parse(const std::string& t)
|
||||||
{
|
{
|
||||||
if (t == "none")
|
if (t == "none")
|
||||||
return LL_NONE;
|
return LL_NONE;
|
||||||
else
|
else
|
||||||
if (t == "debug")
|
if (t == "debug")
|
||||||
return LL_DEBUG;
|
return LL_DEBUG;
|
||||||
else
|
else
|
||||||
if (t == "critical")
|
if (t == "critical")
|
||||||
return LL_CRITICAL;
|
return LL_CRITICAL;
|
||||||
else
|
else
|
||||||
if (t == "info")
|
if (t == "info")
|
||||||
return LL_INFO;
|
return LL_INFO;
|
||||||
else
|
else
|
||||||
if (t == "media")
|
if (t == "media")
|
||||||
return LL_MEDIA;
|
return LL_MEDIA;
|
||||||
else
|
else
|
||||||
if (t == "critical")
|
if (t == "error")
|
||||||
return LL_CRITICAL;
|
return LL_ERROR;
|
||||||
else
|
else
|
||||||
if (t == "special")
|
if (t == "special")
|
||||||
return LL_SPECIAL;
|
return LL_SPECIAL;
|
||||||
|
|
||||||
throw std::runtime_error("Bad log param string value.");
|
throw std::runtime_error("Bad log param string value.");
|
||||||
}
|
}
|
||||||
|
|
@ -63,232 +63,232 @@ ice::Logger ice::GLogger;
|
||||||
const char* ice::Logger::TabPrefix = " ";
|
const char* ice::Logger::TabPrefix = " ";
|
||||||
|
|
||||||
Logger::Logger()
|
Logger::Logger()
|
||||||
:mStream(nullptr)
|
:mStream(nullptr)
|
||||||
{
|
{
|
||||||
mFile = nullptr;
|
mFile = nullptr;
|
||||||
mUseDebugWindow = false;
|
mUseDebugWindow = false;
|
||||||
mDelegate = nullptr;
|
mDelegate = nullptr;
|
||||||
mLevel = LL_DEBUG;
|
mLevel = LL_DEBUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::~Logger()
|
Logger::~Logger()
|
||||||
{
|
{
|
||||||
//LogGuard l(mGuard);
|
//LogGuard l(mGuard);
|
||||||
if (mFile)
|
if (mFile)
|
||||||
{
|
{
|
||||||
fclose(mFile);
|
fclose(mFile);
|
||||||
mFile = NULL;
|
mFile = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Logger::useDebugWindow(bool enable)
|
Logger::useDebugWindow(bool enable)
|
||||||
{
|
{
|
||||||
LogGuard l(mGuard);
|
LogGuard l(mGuard);
|
||||||
|
|
||||||
mUseDebugWindow = enable;
|
mUseDebugWindow = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Logger::useFile(const char* filepath)
|
Logger::useFile(const char* filepath)
|
||||||
{
|
{
|
||||||
LogGuard l(mGuard);
|
LogGuard l(mGuard);
|
||||||
|
|
||||||
mLogPath = filepath ? filepath : "";
|
mLogPath = filepath ? filepath : "";
|
||||||
if (mLogPath.empty())
|
if (mLogPath.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FILE* f = fopen(filepath, "at");
|
FILE* f = fopen(filepath, "at");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (mFile)
|
if (mFile)
|
||||||
fclose(mFile);
|
fclose(mFile);
|
||||||
mFile = f;
|
mFile = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
fprintf(f, "New log chunk starts here.\n");
|
fprintf(f, "New log chunk starts here.\n");
|
||||||
fflush(f);
|
fflush(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Logger::useNull()
|
Logger::useNull()
|
||||||
{
|
{
|
||||||
LogGuard l(mGuard);
|
LogGuard l(mGuard);
|
||||||
|
|
||||||
mUseDebugWindow = false;
|
mUseDebugWindow = false;
|
||||||
if (mFile)
|
if (mFile)
|
||||||
{
|
{
|
||||||
fflush(mFile);
|
fflush(mFile);
|
||||||
fclose(mFile);
|
fclose(mFile);
|
||||||
mFile = NULL;
|
mFile = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDelegate = NULL;
|
mDelegate = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::closeFile()
|
void Logger::closeFile()
|
||||||
{
|
{
|
||||||
LogGuard l(mGuard);
|
LogGuard l(mGuard);
|
||||||
if (mFile)
|
if (mFile)
|
||||||
{
|
{
|
||||||
fflush(mFile);
|
fflush(mFile);
|
||||||
fclose(mFile);
|
fclose(mFile);
|
||||||
mFile = nullptr;
|
mFile = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::openFile()
|
void Logger::openFile()
|
||||||
{
|
{
|
||||||
LogGuard l(mGuard);
|
LogGuard l(mGuard);
|
||||||
if (mLogPath.empty())
|
if (mLogPath.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
remove(mLogPath.c_str());
|
remove(mLogPath.c_str());
|
||||||
useFile(mLogPath.c_str());
|
useFile(mLogPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Logger::useDelegate(LogHandler* delegate_)
|
void Logger::useDelegate(LogHandler* delegate_)
|
||||||
{
|
{
|
||||||
mDelegate = delegate_;
|
mDelegate = delegate_;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogGuard& Logger::mutex()
|
LogGuard& Logger::mutex()
|
||||||
{
|
{
|
||||||
return mGuard;
|
return mGuard;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogLevel Logger::level()
|
LogLevel Logger::level()
|
||||||
{
|
{
|
||||||
return mLevel;
|
return mLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::setLevel(LogLevel level)
|
void Logger::setLevel(LogLevel level)
|
||||||
{
|
{
|
||||||
mLevel = level;
|
mLevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::beginLine(LogLevel level, const char* filename, int linenumber, const char* subsystem)
|
void Logger::beginLine(LogLevel level, const char* filename, int linenumber, const char* subsystem)
|
||||||
{
|
{
|
||||||
mMsgLevel = level;
|
mMsgLevel = level;
|
||||||
mStream = new std::ostringstream();
|
mStream = new std::ostringstream();
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
const char* filenamestart = strrchr(filename, '\\');
|
const char* filenamestart = strrchr(filename, '\\');
|
||||||
#else
|
#else
|
||||||
const char* filenamestart = strrchr(filename, '/');
|
const char* filenamestart = strrchr(filename, '/');
|
||||||
#endif
|
#endif
|
||||||
if (!filenamestart)
|
if (!filenamestart)
|
||||||
filenamestart = filename;
|
filenamestart = filename;
|
||||||
else
|
else
|
||||||
filenamestart++;
|
filenamestart++;
|
||||||
|
|
||||||
mFilename = filenamestart;
|
mFilename = filenamestart;
|
||||||
mLine = linenumber;
|
mLine = linenumber;
|
||||||
mSubsystem = subsystem;
|
mSubsystem = subsystem;
|
||||||
|
|
||||||
//*mStream << std::setw(8) << ICETimeHelper::timestamp() << " | " << std::setw(8) << ThreadInfo::currentThread() << " | " << std::setw(30) << filenamestart << " | " << std::setw(4) << linenumber << " | " << std::setw(12) << subsystem << " | ";
|
//*mStream << std::setw(8) << ICETimeHelper::timestamp() << " | " << std::setw(8) << ThreadInfo::currentThread() << " | " << std::setw(30) << filenamestart << " | " << std::setw(4) << linenumber << " | " << std::setw(12) << subsystem << " | ";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Logger::endLine()
|
Logger::endLine()
|
||||||
{
|
{
|
||||||
*mStream << std::endl;
|
*mStream << std::endl;
|
||||||
*mStream << std::flush;
|
*mStream << std::flush;
|
||||||
mStream->flush();
|
mStream->flush();
|
||||||
|
|
||||||
std::ostringstream result;
|
std::ostringstream result;
|
||||||
result << std::setw(8) << ICETimeHelper::timestamp() << " | " << std::setw(8) << ThreadInfo::currentThread() << " | " << std::setw(30) << mFilename.c_str() << " | " << std::setw(4) << mLine << " | " << std::setw(12) << mSubsystem.c_str() << " | " << mStream->str().c_str();
|
result << std::setw(8) << ICETimeHelper::timestamp() << " | " << std::setw(8) << ThreadInfo::currentThread() << " | " << std::setw(30) << mFilename.c_str() << " | " << std::setw(4) << mLine << " | " << std::setw(12) << mSubsystem.c_str() << " | " << mStream->str().c_str();
|
||||||
|
|
||||||
std::string t = result.str();
|
std::string t = result.str();
|
||||||
if (mUseDebugWindow)
|
if (mUseDebugWindow)
|
||||||
#ifdef TARGET_WIN
|
#ifdef TARGET_WIN
|
||||||
OutputDebugStringA(t.c_str());
|
OutputDebugStringA(t.c_str());
|
||||||
#elif defined(TARGET_ANDROID)
|
#elif defined(TARGET_ANDROID)
|
||||||
if (t.size() > 512)
|
if (t.size() > 512)
|
||||||
{
|
{
|
||||||
std::string cut = t; cut.erase(480); // Erase tail of string
|
std::string cut = t; cut.erase(480); // Erase tail of string
|
||||||
cut += "\r\n... [cut]";
|
cut += "\r\n... [cut]";
|
||||||
__android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", cut.c_str());
|
__android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", cut.c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
__android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", t.c_str());
|
__android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", t.c_str());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::cerr << result.str() << std::endl << std::flush;
|
std::cerr << result.str() << std::endl << std::flush;
|
||||||
#endif
|
#endif
|
||||||
if (mFile)
|
if (mFile)
|
||||||
{
|
{
|
||||||
fprintf(mFile, "%s", result.str().c_str());
|
fprintf(mFile, "%s", result.str().c_str());
|
||||||
fflush(mFile);
|
fflush(mFile);
|
||||||
}
|
}
|
||||||
if (mDelegate)
|
if (mDelegate)
|
||||||
mDelegate->onIceLog(mMsgLevel, mFilename, mLine, mSubsystem, mStream->str());
|
mDelegate->onIceLog(mMsgLevel, mFilename, mLine, mSubsystem, mStream->str());
|
||||||
|
|
||||||
delete mStream; mStream = NULL;
|
delete mStream; mStream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator << (const char* data)
|
Logger::operator << (const char* data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator << (const wchar_t* data)
|
Logger::operator << (const wchar_t* data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator << (const int data)
|
Logger::operator << (const int data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator << (const float data)
|
Logger::operator << (const float data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator<<(const int64_t data)
|
Logger::operator<<(const int64_t data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator<<(const unsigned int data)
|
Logger::operator<<(const unsigned int data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator<<(const uint64_t data)
|
Logger::operator<<(const uint64_t data)
|
||||||
{
|
{
|
||||||
*mStream << data;
|
*mStream << data;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Logger&
|
Logger&
|
||||||
Logger::operator << (const std::string& data)
|
Logger::operator << (const std::string& data)
|
||||||
{
|
{
|
||||||
*mStream << data.c_str();
|
*mStream << data.c_str();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public:
|
||||||
class LogHandler
|
class LogHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~LogHandler() {}
|
||||||
virtual void onIceLog(LogLevel level, const std::string& filename, int line, const std::string& subsystem, const std::string& msg) = 0;
|
virtual void onIceLog(LogLevel level, const std::string& filename, int line, const std::string& subsystem, const std::string& msg) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue