summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-12 11:26:42 +0200
committermadmaxoft <github@xoft.cz>2013-10-12 11:26:42 +0200
commit420e164ea6d677c8a114427a350f1e17e86b9be0 (patch)
treec409d86898d792cfebe9d1e4f87f2908114fd31c /source
parentUpdated BiomeVisualiser to compile again. (diff)
downloadcuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar.gz
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar.bz2
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar.lz
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar.xz
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.tar.zst
cuberite-420e164ea6d677c8a114427a350f1e17e86b9be0.zip
Diffstat (limited to '')
-rw-r--r--source/MCLogger.cpp47
-rw-r--r--source/MCLogger.h18
2 files changed, 43 insertions, 22 deletions
diff --git a/source/MCLogger.cpp b/source/MCLogger.cpp
index 2870d8ba1..4f3e5dc0f 100644
--- a/source/MCLogger.cpp
+++ b/source/MCLogger.cpp
@@ -37,24 +37,7 @@ cMCLogger::cMCLogger(void)
{
AString FileName;
Printf(FileName, "LOG_%d.txt", (int)time(NULL));
- m_Log = new cLog(FileName);
- m_Log->Log("--- Started Log ---\n");
-
- s_MCLogger = this;
-
- #ifdef _WIN32
- // See whether we are writing to a console the default console attrib:
- g_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
- if (g_ShouldColorOutput)
- {
- CONSOLE_SCREEN_BUFFER_INFO sbi;
- GetConsoleScreenBufferInfo(g_Console, &sbi);
- g_DefaultConsoleAttrib = sbi.wAttributes;
- }
- #elif defined (__linux) && !defined(ANDROID_NDK)
- g_ShouldColorOutput = isatty(fileno(stdout));
- // TODO: Check if the terminal supports colors, somehow?
- #endif
+ InitLog(FileName);
}
@@ -63,7 +46,7 @@ cMCLogger::cMCLogger(void)
cMCLogger::cMCLogger(const AString & a_FileName)
{
- m_Log = new cLog(a_FileName);
+ InitLog(a_FileName);
}
@@ -84,6 +67,32 @@ cMCLogger::~cMCLogger()
+void cMCLogger::InitLog(const AString & a_FileName)
+{
+ m_Log = new cLog(a_FileName);
+ m_Log->Log("--- Started Log ---\n");
+
+ s_MCLogger = this;
+
+ #ifdef _WIN32
+ // See whether we are writing to a console the default console attrib:
+ g_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
+ if (g_ShouldColorOutput)
+ {
+ CONSOLE_SCREEN_BUFFER_INFO sbi;
+ GetConsoleScreenBufferInfo(g_Console, &sbi);
+ g_DefaultConsoleAttrib = sbi.wAttributes;
+ }
+ #elif defined (__linux) && !defined(ANDROID_NDK)
+ g_ShouldColorOutput = isatty(fileno(stdout));
+ // TODO: Check if the terminal supports colors, somehow?
+ #endif
+}
+
+
+
+
+
void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
{
switch( a_LogType )
diff --git a/source/MCLogger.h b/source/MCLogger.h
index 6f7d34e66..c949a4cdf 100644
--- a/source/MCLogger.h
+++ b/source/MCLogger.h
@@ -13,8 +13,12 @@ class cLog;
class cMCLogger // tolua_export
{ // tolua_export
public: // tolua_export
+ /// Creates a logger with the default filename, "logs/LOG_<timestamp>.log"
cMCLogger(void);
+
+ /// Creates a logger with the specified filename inside "logs" folder
cMCLogger(const AString & a_FileName); // tolua_export
+
~cMCLogger(); // tolua_export
void Log(const char* a_Format, va_list a_ArgList);
@@ -34,17 +38,25 @@ private:
csError,
} ;
+ cCriticalSection m_CriticalSection;
+ cLog * m_Log;
+ static cMCLogger * s_MCLogger;
+
+
/// Sets the specified color scheme in the terminal (TODO: if coloring available)
void SetColor(eColorScheme a_Scheme);
/// Resets the color back to whatever is the default in the terminal
void ResetColor(void);
- cCriticalSection m_CriticalSection;
- cLog * m_Log;
- static cMCLogger * s_MCLogger;
+ /// Common initialization for all constructors, creates a logfile with the specified name and assigns s_MCLogger to this
+ void InitLog(const AString & a_FileName);
}; // tolua_export
+
+
+
+
extern void LOG(const char* a_Format, ...);
extern void LOGINFO(const char* a_Format, ...);
extern void LOGWARN(const char* a_Format, ...);