1
0
Fork 0

LOG() API reads the LogLevel from the cCompositeChat's MessageType.

This commit is contained in:
madmaxoft 2014-04-01 09:32:14 +02:00
parent 58f2550321
commit 7aa6a3b866
6 changed files with 81 additions and 24 deletions

View File

@ -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 =
{

View File

@ -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;
}

View File

@ -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())

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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
{