summaryrefslogtreecommitdiffstats
path: root/src/Logger.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-08-20 22:25:05 +0200
committerHowaner <franzi.moos@googlemail.com>2014-08-20 22:25:05 +0200
commitf7774ec33638bfc30cc29c1f70850a6072a31c93 (patch)
treec2c2896b87de9241b1555e4e2580aa6b3f401870 /src/Logger.cpp
parentRevert "Removes the fire if the block under the fire was broken." (diff)
parentMerge pull request #1335 from mc-server/CodeFixes (diff)
downloadcuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar.gz
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar.bz2
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar.lz
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar.xz
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.tar.zst
cuberite-f7774ec33638bfc30cc29c1f70850a6072a31c93.zip
Diffstat (limited to 'src/Logger.cpp')
-rw-r--r--src/Logger.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/Logger.cpp b/src/Logger.cpp
new file mode 100644
index 000000000..cb528e8ab
--- /dev/null
+++ b/src/Logger.cpp
@@ -0,0 +1,145 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "OSSupport/IsThread.h"
+#ifdef _WIN32
+ #include <time.h>
+#endif
+
+
+
+
+
+cLogger & cLogger::GetInstance(void)
+{
+ static cLogger Instance;
+ return Instance;
+}
+
+
+
+
+
+void cLogger::InitiateMultithreading()
+{
+ GetInstance();
+}
+
+
+
+
+
+void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
+{
+ time_t rawtime;
+ time(&rawtime);
+
+ struct tm * timeinfo;
+ #ifdef _MSC_VER
+ struct tm timeinforeal;
+ timeinfo = &timeinforeal;
+ localtime_s(timeinfo, &rawtime);
+ #else
+ timeinfo = localtime(&rawtime);
+ #endif
+
+ AString Line;
+ #ifdef _DEBUG
+ Printf(Line, "[%04lx|%02d:%02d:%02d] %s\n", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #else
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ #endif
+
+
+ cCSLock Lock(m_CriticalSection);
+ for (size_t i = 0; i < m_LogListeners.size(); i++)
+ {
+ m_LogListeners[i]->Log(Line, a_LogLevel);
+ }
+}
+
+
+
+
+
+void cLogger::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList)
+{
+ AString Message;
+ AppendVPrintf(Message, a_Format, a_ArgList);
+ LogSimple(Message, a_LogLevel);
+}
+
+
+
+
+
+void cLogger::AttachListener(cListener * a_Listener)
+{
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.push_back(a_Listener);
+}
+
+
+
+
+
+void cLogger::DetachListener(cListener * a_Listener)
+{
+ cCSLock Lock(m_CriticalSection);
+ m_LogListeners.erase(std::remove(m_LogListeners.begin(), m_LogListeners.end(), a_Listener));
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Global functions
+
+void LOG(const char * a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log(a_Format, cLogger::llRegular, argList);
+ va_end(argList);
+}
+
+
+
+
+
+void LOGINFO(const char * a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llInfo, argList);
+ va_end(argList);
+}
+
+
+
+
+
+void LOGWARN(const char * a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llWarning, argList);
+ va_end(argList);
+}
+
+
+
+
+
+void LOGERROR(const char * a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cLogger::GetInstance().Log( a_Format, cLogger::llError, argList);
+ va_end(argList);
+}
+
+
+
+