diff options
author | Peter Bell <peterbell10@live.co.uk> | 2020-05-15 13:54:08 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-05-16 10:39:05 +0200 |
commit | 6dee68cb630a73e62935ff0810fffe6586b08ef0 (patch) | |
tree | b4993be4eac159336960e77362754c69ef09e5af | |
parent | Update logging code to reduce unnecessary string copying: (diff) | |
download | cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar.gz cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar.bz2 cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar.lz cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar.xz cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.tar.zst cuberite-6dee68cb630a73e62935ff0810fffe6586b08ef0.zip |
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index b0c18b32e..7f7cb8ea9 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -33,7 +33,6 @@ #include "../HTTP/UrlParser.h" #include "../Item.h" #include "../LineBlockTracer.h" -#include "../Logger.h" #include "../Server.h" #include "../Root.h" #include "../StringCompression.h" @@ -368,23 +367,19 @@ static int tolua_StringSplitAndTrim(lua_State * tolua_S) /** Retrieves the log message from the first param on the Lua stack. Can take either a string or a cCompositeChat. */ -static AString GetLogMessage(lua_State * tolua_S) +static void LogFromLuaStack(lua_State * tolua_S, eLogLevel a_LogLevel) { tolua_Error err; if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err)) { - return static_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr))->ExtractText(); + auto Msg = static_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr))->ExtractText(); + Logger::LogSimple(Msg, a_LogLevel); + return; } - else - { - size_t len = 0; - const char * str = lua_tolstring(tolua_S, 1, &len); - if (str != nullptr) - { - return AString(str, len); - } - } - return ""; + + size_t len = 0; + const char * str = lua_tolstring(tolua_S, 1, &len); + Logger::LogSimple(std::string_view(str, len), a_LogLevel); } @@ -406,11 +401,13 @@ static int tolua_LOG(lua_State * tolua_S) tolua_Error err; if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err)) { - LogLevel = cCompositeChat::MessageTypeToLogLevel(static_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr))->GetMessageType()); + LogLevel = cCompositeChat::MessageTypeToLogLevel( + static_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr))->GetMessageType() + ); } // Log the message: - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), LogLevel); + LogFromLuaStack(tolua_S, LogLevel); return 0; } @@ -428,7 +425,7 @@ static int tolua_LOGINFO(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), eLogLevel::Info); + LogFromLuaStack(tolua_S, eLogLevel::Info); return 0; } @@ -446,7 +443,7 @@ static int tolua_LOGWARN(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), eLogLevel::Warning); + LogFromLuaStack(tolua_S, eLogLevel::Warning); return 0; } @@ -464,7 +461,7 @@ static int tolua_LOGERROR(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), eLogLevel::Error); + LogFromLuaStack(tolua_S, eLogLevel::Error); return 0; } |