summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua4
-rw-r--r--src/Bindings/ManualBindings.cpp17
-rw-r--r--src/CompositeChat.cpp23
-rw-r--r--src/CompositeChat.h4
-rw-r--r--src/MCLogger.cpp24
-rw-r--r--src/MCLogger.h33
6 files changed, 81 insertions, 24 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index b1b660bb0..28e7744ed 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2665,8 +2665,8 @@ end
ItemTypeToString = {Params = "ItemType", Return = "string", Notes = "Returns the string representation of ItemType "},
LOG =
{
- {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text) "},
- {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console using 'normal' severity (gray text) "},
+ {Params = "string", Notes = "Logs a text into the server console using 'normal' severity (gray text)"},
+ {Params = "{{cCompositeChat|CompositeChat}}", Notes = "Logs the {{cCompositeChat}}'s human-readable text into the server console. The severity is converted from the CompositeChat's MessageType."},
},
LOGERROR =
{
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 95cd5e904..9d1a367df 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -143,7 +143,16 @@ static AString GetLogMessage(lua_State * tolua_S)
static int tolua_LOG(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 0);
+ // If the param is a cCompositeChat, read the log level from it:
+ cMCLogger::eLogLevel LogLevel = cMCLogger::llRegular;
+ tolua_Error err;
+ if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err))
+ {
+ LogLevel = cCompositeChat::MessageTypeToLogLevel(((cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL))->GetMessageType());
+ }
+
+ // Log the message:
+ cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
return 0;
}
@@ -153,7 +162,7 @@ static int tolua_LOG(lua_State * tolua_S)
static int tolua_LOGINFO(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 1);
+ cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llInfo);
return 0;
}
@@ -163,7 +172,7 @@ static int tolua_LOGINFO(lua_State * tolua_S)
static int tolua_LOGWARN(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 2);
+ cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llWarning);
return 0;
}
@@ -173,7 +182,7 @@ static int tolua_LOGWARN(lua_State * tolua_S)
static int tolua_LOGERROR(lua_State * tolua_S)
{
- cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 3);
+ cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), cMCLogger::llError);
return 0;
}
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index 918e4f90e..c70ef1070 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -343,6 +343,29 @@ AString cCompositeChat::ExtractText(void) const
+cMCLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageType)
+{
+ switch (a_MessageType)
+ {
+ case mtCustom: return cMCLogger::llRegular;
+ case mtFailure: return cMCLogger::llWarning;
+ case mtInformation: return cMCLogger::llInfo;
+ case mtSuccess: return cMCLogger::llRegular;
+ case mtWarning: return cMCLogger::llWarning;
+ case mtFatal: return cMCLogger::llError;
+ case mtDeath: return cMCLogger::llRegular;
+ case mtPrivateMessage: return cMCLogger::llRegular;
+ case mtJoin: return cMCLogger::llRegular;
+ case mtLeave: return cMCLogger::llRegular;
+ }
+ ASSERT(!"Unhandled MessageType");
+ return cMCLogger::llError;
+}
+
+
+
+
+
void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle)
{
if (a_AddStyle.empty())
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 0f56cde9b..5b9c5f612 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -173,6 +173,10 @@ public:
const cParts & GetParts(void) const { return m_Parts; }
+ /** Converts the MessageType to a LogLevel value.
+ Used by the logging bindings when logging a cCompositeChat object. */
+ static cMCLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
+
protected:
/** All the parts that */
cParts m_Parts;
diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp
index 4f3e5dc0f..509833f37 100644
--- a/src/MCLogger.cpp
+++ b/src/MCLogger.cpp
@@ -93,25 +93,35 @@ void cMCLogger::InitLog(const AString & a_FileName)
-void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
+void cMCLogger::LogSimple(const char * a_Text, eLogLevel a_LogLevel)
{
- switch( a_LogType )
+ switch (a_LogLevel)
{
- case 0:
+ case llRegular:
+ {
LOG("%s", a_Text);
break;
- case 1:
+ }
+ case llInfo:
+ {
LOGINFO("%s", a_Text);
break;
- case 2:
+ }
+ case llWarning:
+ {
LOGWARN("%s", a_Text);
break;
- case 3:
+ }
+ case llError:
+ {
LOGERROR("%s", a_Text);
break;
+ }
default:
- LOG("(#%d#: %s", a_LogType, a_Text);
+ {
+ LOG("(#%d#: %s", (int)a_LogLevel, a_Text);
break;
+ }
}
}
diff --git a/src/MCLogger.h b/src/MCLogger.h
index 996e60329..c0150c124 100644
--- a/src/MCLogger.h
+++ b/src/MCLogger.h
@@ -10,25 +10,36 @@ class cLog;
-class cMCLogger // tolua_export
-{ // tolua_export
-public: // tolua_export
- /// Creates a logger with the default filename, "logs/LOG_<timestamp>.log"
+// tolua_begin
+class cMCLogger
+{
+public:
+ enum eLogLevel
+ {
+ llRegular,
+ llInfo,
+ llWarning,
+ llError,
+ };
+ // tolua_end
+
+ /** Creates a logger with the default filename, "logs/LOG_<timestamp>.log" */
cMCLogger(void);
- /// Creates a logger with the specified filename inside "logs" folder
+ /** 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) FORMATSTRING(2, 0);
- void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Log (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Info (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Warn (const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
+ void Error(const char * a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
- void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export
+ /** Logs the simple text message at the specified log level. */
+ void LogSimple(const char * a_Text, eLogLevel a_LogLevel = llRegular); // tolua_export
- static cMCLogger* GetInstance();
+ static cMCLogger * GetInstance();
private:
enum eColorScheme
{