diff --git a/src/engine/endpoint/EP_Engine.cpp b/src/engine/endpoint/EP_Engine.cpp index 8500b9cc..913b33e7 100644 --- a/src/engine/endpoint/EP_Engine.cpp +++ b/src/engine/endpoint/EP_Engine.cpp @@ -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(); if (level <= resip::Log::Crit) - ICELogCritical(<< ss.str()); + ICELogCritical(<< ss.str()) else if (level <= resip::Log::Warning) ICELogError(<< ss.str().c_str()) diff --git a/src/libs/ice/ICELog.cpp b/src/libs/ice/ICELog.cpp index 125f4afa..392b59b2 100644 --- a/src/libs/ice/ICELog.cpp +++ b/src/libs/ice/ICELog.cpp @@ -20,25 +20,25 @@ using namespace ice; LogLevel LogLevelHelper::parse(const std::string& t) { if (t == "none") - return LL_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; + 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 == "error") + return LL_ERROR; + else + if (t == "special") + return LL_SPECIAL; throw std::runtime_error("Bad log param string value."); } @@ -63,232 +63,232 @@ ice::Logger ice::GLogger; const char* ice::Logger::TabPrefix = " "; Logger::Logger() -:mStream(nullptr) + :mStream(nullptr) { - mFile = nullptr; - mUseDebugWindow = false; - mDelegate = nullptr; - mLevel = LL_DEBUG; + mFile = nullptr; + mUseDebugWindow = false; + mDelegate = nullptr; + mLevel = LL_DEBUG; } Logger::~Logger() { - //LogGuard l(mGuard); - if (mFile) - { - fclose(mFile); - mFile = NULL; - } + //LogGuard l(mGuard); + if (mFile) + { + fclose(mFile); + mFile = NULL; + } } void Logger::useDebugWindow(bool enable) { - LogGuard l(mGuard); + LogGuard l(mGuard); - mUseDebugWindow = enable; + mUseDebugWindow = enable; } void Logger::useFile(const char* filepath) { - LogGuard l(mGuard); + LogGuard l(mGuard); - mLogPath = filepath ? filepath : ""; - if (mLogPath.empty()) - return; + mLogPath = filepath ? filepath : ""; + if (mLogPath.empty()) + return; - FILE* f = fopen(filepath, "at"); - if (f) - { - if (mFile) - fclose(mFile); - mFile = f; - } + FILE* f = fopen(filepath, "at"); + if (f) + { + if (mFile) + fclose(mFile); + mFile = f; + } - if (f) - { - fprintf(f, "New log chunk starts here.\n"); - fflush(f); - } + if (f) + { + fprintf(f, "New log chunk starts here.\n"); + fflush(f); + } } void Logger::useNull() { - LogGuard l(mGuard); + LogGuard l(mGuard); - mUseDebugWindow = false; - if (mFile) - { - fflush(mFile); - fclose(mFile); - mFile = NULL; - } + mUseDebugWindow = false; + if (mFile) + { + fflush(mFile); + fclose(mFile); + mFile = NULL; + } - mDelegate = NULL; + mDelegate = NULL; } void Logger::closeFile() { - LogGuard l(mGuard); - if (mFile) - { - fflush(mFile); - fclose(mFile); - mFile = nullptr; - } + LogGuard l(mGuard); + if (mFile) + { + fflush(mFile); + fclose(mFile); + mFile = nullptr; + } } void Logger::openFile() { - LogGuard l(mGuard); - if (mLogPath.empty()) - return; + LogGuard l(mGuard); + if (mLogPath.empty()) + return; - remove(mLogPath.c_str()); - useFile(mLogPath.c_str()); + remove(mLogPath.c_str()); + useFile(mLogPath.c_str()); } void Logger::useDelegate(LogHandler* delegate_) { - mDelegate = delegate_; + mDelegate = delegate_; } LogGuard& Logger::mutex() { - return mGuard; + return mGuard; } LogLevel Logger::level() { - return mLevel; + return mLevel; } void Logger::setLevel(LogLevel level) { - mLevel = level; + mLevel = level; } void Logger::beginLine(LogLevel level, const char* filename, int linenumber, const char* subsystem) { - mMsgLevel = level; - mStream = new std::ostringstream(); + mMsgLevel = level; + mStream = new std::ostringstream(); #ifdef WIN32 - const char* filenamestart = strrchr(filename, '\\'); + const char* filenamestart = strrchr(filename, '\\'); #else - const char* filenamestart = strrchr(filename, '/'); + const char* filenamestart = strrchr(filename, '/'); #endif - if (!filenamestart) - filenamestart = filename; - else - filenamestart++; - - mFilename = filenamestart; - mLine = linenumber; - 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 << " | "; + if (!filenamestart) + filenamestart = filename; + else + filenamestart++; + + mFilename = filenamestart; + mLine = linenumber; + 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 << " | "; } void Logger::endLine() { - *mStream << std::endl; - *mStream << std::flush; - mStream->flush(); + *mStream << std::endl; + *mStream << std::flush; + mStream->flush(); - 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(); + 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(); - std::string t = result.str(); - if (mUseDebugWindow) + std::string t = result.str(); + if (mUseDebugWindow) #ifdef TARGET_WIN - OutputDebugStringA(t.c_str()); + OutputDebugStringA(t.c_str()); #elif defined(TARGET_ANDROID) - if (t.size() > 512) - { - std::string cut = t; cut.erase(480); // Erase tail of string - cut += "\r\n... [cut]"; - __android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", cut.c_str()); - } - else { - __android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", t.c_str()); - } + if (t.size() > 512) + { + std::string cut = t; cut.erase(480); // Erase tail of string + cut += "\r\n... [cut]"; + __android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", cut.c_str()); + } + else { + __android_log_print(ANDROID_LOG_INFO, "VoipAgent", "%s", t.c_str()); + } #else - std::cerr << result.str() << std::endl << std::flush; + std::cerr << result.str() << std::endl << std::flush; #endif - if (mFile) - { - fprintf(mFile, "%s", result.str().c_str()); - fflush(mFile); - } - if (mDelegate) - mDelegate->onIceLog(mMsgLevel, mFilename, mLine, mSubsystem, mStream->str()); - - delete mStream; mStream = NULL; + if (mFile) + { + fprintf(mFile, "%s", result.str().c_str()); + fflush(mFile); + } + if (mDelegate) + mDelegate->onIceLog(mMsgLevel, mFilename, mLine, mSubsystem, mStream->str()); + + delete mStream; mStream = NULL; } Logger& Logger::operator << (const char* data) { - *mStream << data; + *mStream << data; - return *this; + return *this; } Logger& Logger::operator << (const wchar_t* data) { - *mStream << data; + *mStream << data; - return *this; + return *this; } Logger& Logger::operator << (const int data) { - *mStream << data; + *mStream << data; - return *this; + return *this; } Logger& Logger::operator << (const float data) { - *mStream << data; + *mStream << data; - return *this; + return *this; } Logger& Logger::operator<<(const int64_t data) { - *mStream << data; - return *this; + *mStream << data; + return *this; } Logger& Logger::operator<<(const unsigned int data) { - *mStream << data; - return *this; + *mStream << data; + return *this; } Logger& Logger::operator<<(const uint64_t data) { - *mStream << data; - return *this; + *mStream << data; + return *this; } Logger& Logger::operator << (const std::string& data) { - *mStream << data.c_str(); - return *this; + *mStream << data.c_str(); + return *this; } diff --git a/src/libs/ice/ICELog.h b/src/libs/ice/ICELog.h index d0f0af0f..15d90bb8 100644 --- a/src/libs/ice/ICELog.h +++ b/src/libs/ice/ICELog.h @@ -44,6 +44,7 @@ public: class LogHandler { public: + virtual ~LogHandler() {} virtual void onIceLog(LogLevel level, const std::string& filename, int line, const std::string& subsystem, const std::string& msg) = 0; };