-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.54..v0.2.55 changeset Log.cpp
Garret Voltz edited this page Aug 14, 2020
·
1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/util/Log.cpp b/hoot-core/src/main/cpp/hoot/core/util/Log.cpp
index 9199d55..101c45d 100644
--- a/hoot-core/src/main/cpp/hoot/core/util/Log.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/util/Log.cpp
@@ -22,7 +22,7 @@
* This will properly maintain the copyright information. DigitalGlobe
* copyrights will be updated automatically.
*
- * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
*/
#include "Log.h"
@@ -47,29 +47,24 @@ namespace hoot
QString Log::LOG_WARN_LIMIT_REACHED_MESSAGE = "Reached the maximum number of allowed warning messages for this class set by the setting log.warn.message.limit. Silencing additional warning messages for this class...";
int Log::_warnMessageLimit = 0;
-std::shared_ptr<Log> Log::_theInstance = NULL;
+Log& Log::getInstance()
+{
+ // Local static singleton instance
+ static Log instance;
+ return instance;
+}
void myLoggerFunction(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
Log::WarningLevel l = Log::Fatal;
switch(type)
{
- case QtDebugMsg:
- l = Log::Debug;
- break;
- case QtWarningMsg:
- l = Log::Warn;
- break;
- case QtCriticalMsg:
- l = Log::Error;
- break;
- case QtFatalMsg:
- l = Log::Fatal;
- break;
- case QtInfoMsg:
- l = Log::Info;
+ case QtDebugMsg: l = Log::Debug; break;
+ case QtWarningMsg: l = Log::Warn; break;
+ case QtCriticalMsg: l = Log::Error; break;
+ case QtFatalMsg: l = Log::Fatal; break;
+ case QtInfoMsg: l = Log::Info; break;
}
-
Log::getInstance().log(l, msg, context.file, context.function, context.line);
}
@@ -78,31 +73,21 @@ static void cplErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
Log::WarningLevel l = Log::Fatal;
switch (eErrClass)
{
- case CE_None:
- l = Log::None;
- break;
- case CE_Debug:
- l = Log::Debug;
- break;
- case CE_Warning:
- l = Log::Warn;
- break;
- case CE_Failure:
- l = Log::Error;
- break;
- case CE_Fatal:
- l = Log::Fatal;
- break;
+ case CE_None: l = Log::None; break;
+ case CE_Debug: l = Log::Debug; break;
+ case CE_Warning: l = Log::Warn; break;
+ case CE_Failure: l = Log::Error; break;
+ case CE_Fatal: l = Log::Fatal; break;
}
-
stringstream ss;
ss << "CPL Error #: " << err_no << " " << msg;
Log::getInstance().log(l, ss.str());
}
Log::Log()
+ : _level(Log::Info),
+ _classFilterInitialized(false)
{
- _level = Log::Info;
qInstallMessageHandler(myLoggerFunction);
CPLSetErrorHandler(cplErrorHandler);
}
@@ -110,9 +95,7 @@ Log::Log()
int Log::getWarnMessageLimit()
{
if (_warnMessageLimit == 0)
- {
_warnMessageLimit = ConfigOptions().getLogWarnMessageLimit();
- }
return _warnMessageLimit;
}
@@ -120,63 +103,38 @@ Log::WarningLevel Log::levelFromString(QString l)
{
l = l.toLower();
if (l == "none")
- {
return None;
- }
- if (l == "trace")
- {
+ else if (l == "trace")
return Trace;
- }
- if (l == "debug")
- {
+ else if (l == "debug")
return Debug;
- }
- if (l == "info")
- {
+ else if (l == "info")
return Info;
- }
- if (l == "status")
- {
+ else if (l == "status")
return Status;
- }
- if (l == "warn")
- {
+ else if (l == "warn")
return Warn;
- }
- if (l == "error")
- {
+ else if (l == "error")
return Error;
- }
- if (l == "fatal")
- {
+ else if (l == "fatal")
return Fatal;
- }
-
- throw IllegalArgumentException("Unexpected log level string: " + l);
+ else
+ throw IllegalArgumentException("Unexpected log level string: " + l);
}
QString Log::levelToString(WarningLevel l)
{
switch(l)
{
- case None:
- return "NONE";
- case Trace:
- return "TRACE";
- case Debug:
- return "DEBUG";
- case Info:
- return "INFO";
- case Status:
- return "STATUS";
- case Warn:
- return "WARN";
- case Error:
- return "ERROR";
- case Fatal:
- return "FATAL";
- default:
- return "UNK";
+ case None: return "NONE";
+ case Trace: return "TRACE";
+ case Debug: return "DEBUG";
+ case Info: return "INFO";
+ case Status: return "STATUS";
+ case Warn: return "WARN";
+ case Error: return "ERROR";
+ case Fatal: return "FATAL";
+ default: return "UNK";
}
}