feat(Logging): add support new logging (#17)

This commit is contained in:
Kargatum
2022-01-28 00:05:21 +07:00
committed by GitHub
parent 5ead47b733
commit ee4e38fa04
5 changed files with 28 additions and 28 deletions

View File

@@ -80,7 +80,7 @@ void ElunaInstanceAI::Load(const char* data)
} }
else else
{ {
ELUNA_LOG_ERROR("Error while loading instance data: Expected data to be a table (type 5), got type %d instead", lua_type(L, -1)); ELUNA_LOG_ERROR("Error while loading instance data: Expected data to be a table (type 5), got type {} instead", lua_type(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
// Stack: (empty) // Stack: (empty)
@@ -92,7 +92,7 @@ void ElunaInstanceAI::Load(const char* data)
else else
{ {
// Stack: error_message // Stack: error_message
ELUNA_LOG_ERROR("Error while parsing instance data with lua-marshal: %s", lua_tostring(L, -1)); ELUNA_LOG_ERROR("Error while parsing instance data with lua-marshal: {}", lua_tostring(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
// Stack: (empty) // Stack: (empty)
@@ -135,7 +135,7 @@ const char* ElunaInstanceAI::Save() const
if (lua_pcall(L, 1, 1, 0) != 0) if (lua_pcall(L, 1, 1, 0) != 0)
{ {
// Stack: error_message // Stack: error_message
ELUNA_LOG_ERROR("Error while saving: %s", lua_tostring(L, -1)); ELUNA_LOG_ERROR("Error while saving: {}", lua_tostring(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
return NULL; return NULL;
} }

View File

@@ -28,7 +28,7 @@ public:
int args = lua_gettop(L) - top; int args = lua_gettop(L) - top;
if (args < 0 || args > expected) if (args < 0 || args > expected)
{ {
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected); ELUNA_LOG_ERROR("[Eluna]: {} returned unexpected amount of arguments {} out of {}. Report to devs", l->name, args, expected);
ASSERT(false); ASSERT(false);
} }
lua_settop(L, top + expected); lua_settop(L, top + expected);
@@ -263,7 +263,7 @@ public:
ElunaObject** ptrHold = static_cast<ElunaObject**>(lua_newuserdata(L, sizeof(ElunaObject*))); ElunaObject** ptrHold = static_cast<ElunaObject**>(lua_newuserdata(L, sizeof(ElunaObject*)));
if (!ptrHold) if (!ptrHold)
{ {
ELUNA_LOG_ERROR("%s could not create new userdata", tname); ELUNA_LOG_ERROR("{} could not create new userdata", tname);
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
} }
@@ -274,7 +274,7 @@ public:
lua_rawget(L, LUA_REGISTRYINDEX); lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_istable(L, -1)) if (!lua_istable(L, -1))
{ {
ELUNA_LOG_ERROR("%s missing metatable", tname); ELUNA_LOG_ERROR("{} missing metatable", tname);
lua_pop(L, 2); lua_pop(L, 2);
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
@@ -299,7 +299,7 @@ public:
} }
else else
{ {
ELUNA_LOG_ERROR("%s", buff); ELUNA_LOG_ERROR("{}", buff);
} }
return NULL; return NULL;
} }
@@ -332,7 +332,7 @@ public:
int args = lua_gettop(L) - top; int args = lua_gettop(L) - top;
if (args < 0 || args > expected) if (args < 0 || args > expected)
{ {
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected); ELUNA_LOG_ERROR("[Eluna]: {} returned unexpected amount of arguments {} out of {}. Report to devs", l->name, args, expected);
ASSERT(false); ASSERT(false);
} }
lua_settop(L, top + expected); lua_settop(L, top + expected);

View File

@@ -2586,7 +2586,7 @@ namespace LuaGlobalFunctions
*/ */
int PrintInfo(lua_State* L) int PrintInfo(lua_State* L)
{ {
ELUNA_LOG_INFO("%s", GetStackAsString(L).c_str()); ELUNA_LOG_INFO("{}", GetStackAsString(L));
return 0; return 0;
} }
@@ -2597,7 +2597,7 @@ namespace LuaGlobalFunctions
*/ */
int PrintError(lua_State* L) int PrintError(lua_State* L)
{ {
ELUNA_LOG_ERROR("%s", GetStackAsString(L).c_str()); ELUNA_LOG_ERROR("{}", GetStackAsString(L));
return 0; return 0;
} }
@@ -2608,7 +2608,7 @@ namespace LuaGlobalFunctions
*/ */
int PrintDebug(lua_State* L) int PrintDebug(lua_State* L)
{ {
ELUNA_LOG_DEBUG("%s", GetStackAsString(L).c_str()); ELUNA_LOG_DEBUG("{}", GetStackAsString(L));
return 0; return 0;
} }

View File

@@ -132,7 +132,7 @@ void HttpManager::HttpWorkerThread()
std::string path; std::string path;
if (!ParseUrl(req->url, host, path)) { if (!ParseUrl(req->url, host, path)) {
ELUNA_LOG_ERROR("[Eluna]: Could not parse URL %s", req->url.c_str()); ELUNA_LOG_ERROR("[Eluna]: Could not parse URL {}", req->url);
continue; continue;
} }
@@ -145,7 +145,7 @@ void HttpManager::HttpWorkerThread()
httplib::Error err = res.error(); httplib::Error err = res.error();
if (err != httplib::Error::Success) if (err != httplib::Error::Success)
{ {
ELUNA_LOG_ERROR("[Eluna]: HTTP request error: %s", httplib::to_string(err).c_str()); ELUNA_LOG_ERROR("[Eluna]: HTTP request error: {}", httplib::to_string(err));
continue; continue;
} }
@@ -157,7 +157,7 @@ void HttpManager::HttpWorkerThread()
if (!ParseUrl(location, host, path)) if (!ParseUrl(location, host, path))
{ {
ELUNA_LOG_ERROR("[Eluna]: Could not parse URL after redirect: %s", location.c_str()); ELUNA_LOG_ERROR("[Eluna]: Could not parse URL after redirect: {}", location);
continue; continue;
} }
httplib::Client cli2(host); httplib::Client cli2(host);
@@ -171,7 +171,7 @@ void HttpManager::HttpWorkerThread()
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
ELUNA_LOG_ERROR("[Eluna]: HTTP request error: %s", ex.what()); ELUNA_LOG_ERROR("[Eluna]: HTTP request error: {}", ex.what());
} }
delete req; delete req;
@@ -210,7 +210,7 @@ httplib::Result HttpManager::DoRequest(httplib::Client& client, HttpWorkItem* re
return client.Options(path, req->headers); return client.Options(path, req->headers);
} }
ELUNA_LOG_ERROR("[Eluna]: HTTP request error: invalid HTTP verb %s", req->httpVerb.c_str()); ELUNA_LOG_ERROR("[Eluna]: HTTP request error: invalid HTTP verb {}", req->httpVerb));
return client.Get(path, req->headers); return client.Get(path, req->headers);
} }

View File

@@ -118,14 +118,14 @@ void Eluna::LoadScriptPaths()
if (const char* home = getenv("HOME")) if (const char* home = getenv("HOME"))
lua_folderpath.replace(0, 1, home); lua_folderpath.replace(0, 1, home);
#endif #endif
ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str()); ELUNA_LOG_INFO("[Eluna]: Searching scripts from `{}`", lua_folderpath);
lua_requirepath.clear(); lua_requirepath.clear();
GetScripts(lua_folderpath); GetScripts(lua_folderpath);
// Erase last ; // Erase last ;
if (!lua_requirepath.empty()) if (!lua_requirepath.empty())
lua_requirepath.erase(lua_requirepath.end() - 1); lua_requirepath.erase(lua_requirepath.end() - 1);
ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size() + lua_extensions.size()), ElunaUtil::GetTimeDiff(oldMSTime)); ELUNA_LOG_DEBUG("[Eluna]: Loaded {} scripts in {} ms", lua_scripts.size() + lua_extensions.size(), ElunaUtil::GetTimeDiff(oldMSTime));
} }
void Eluna::_ReloadEluna() void Eluna::_ReloadEluna()
@@ -326,7 +326,7 @@ void Eluna::DestroyBindStores()
void Eluna::AddScriptPath(std::string filename, const std::string& fullpath) void Eluna::AddScriptPath(std::string filename, const std::string& fullpath)
{ {
ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `%s`", fullpath.c_str()); ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `{}`", fullpath);
// split file name // split file name
std::size_t extDot = filename.find_last_of('.'); std::size_t extDot = filename.find_last_of('.');
@@ -349,13 +349,13 @@ void Eluna::AddScriptPath(std::string filename, const std::string& fullpath)
lua_extensions.push_back(script); lua_extensions.push_back(script);
else else
lua_scripts.push_back(script); lua_scripts.push_back(script);
ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath add path `%s`", fullpath.c_str()); ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath add path `{}`", fullpath);
} }
// Finds lua script files from given path (including subdirectories) and pushes them to scripts // Finds lua script files from given path (including subdirectories) and pushes them to scripts
void Eluna::GetScripts(std::string path) void Eluna::GetScripts(std::string path)
{ {
ELUNA_LOG_DEBUG("[Eluna]: GetScripts from path `%s`", path.c_str()); ELUNA_LOG_DEBUG("[Eluna]: GetScripts from path `{}`", path);
#ifdef USING_BOOST #ifdef USING_BOOST
boost::filesystem::path someDir(path); boost::filesystem::path someDir(path);
@@ -480,7 +480,7 @@ void Eluna::RunScripts()
// Check that no duplicate names exist // Check that no duplicate names exist
if (loaded.find(it->filename) != loaded.end()) if (loaded.find(it->filename) != loaded.end())
{ {
ELUNA_LOG_ERROR("[Eluna]: Error loading `%s`. File with same name already loaded from `%s`, rename either file", it->filepath.c_str(), loaded[it->filename].c_str()); ELUNA_LOG_ERROR("[Eluna]: Error loading `{}`. File with same name already loaded from `{}`, rename either file", it->filepath, loaded[it->filename]);
continue; continue;
} }
loaded[it->filename] = it->filepath; loaded[it->filename] = it->filepath;
@@ -490,7 +490,7 @@ void Eluna::RunScripts()
if (!lua_isnoneornil(L, -1)) if (!lua_isnoneornil(L, -1))
{ {
lua_pop(L, 1); lua_pop(L, 1);
ELUNA_LOG_DEBUG("[Eluna]: `%s` was already loaded or required", it->filepath.c_str()); ELUNA_LOG_DEBUG("[Eluna]: `{}` was already loaded or required", it->filepath);
continue; continue;
} }
lua_pop(L, 1); lua_pop(L, 1);
@@ -499,7 +499,7 @@ void Eluna::RunScripts()
if (luaL_loadfile(L, it->filepath.c_str())) if (luaL_loadfile(L, it->filepath.c_str()))
{ {
// Stack: package, modules, errmsg // Stack: package, modules, errmsg
ELUNA_LOG_ERROR("[Eluna]: Error loading `%s`", it->filepath.c_str()); ELUNA_LOG_ERROR("[Eluna]: Error loading `{}`", it->filepath);
Report(L); Report(L);
// Stack: package, modules // Stack: package, modules
continue; continue;
@@ -519,14 +519,14 @@ void Eluna::RunScripts()
// Stack: package, modules // Stack: package, modules
// successfully loaded and ran file // successfully loaded and ran file
ELUNA_LOG_DEBUG("[Eluna]: Successfully loaded `%s`", it->filepath.c_str()); ELUNA_LOG_DEBUG("[Eluna]: Successfully loaded `{}`", it->filepath);
++count; ++count;
continue; continue;
} }
} }
// Stack: package, modules // Stack: package, modules
lua_pop(L, 2); lua_pop(L, 2);
ELUNA_LOG_INFO("[Eluna]: Executed %u Lua scripts in %u ms", count, ElunaUtil::GetTimeDiff(oldMSTime)); ELUNA_LOG_INFO("[Eluna]: Executed {} Lua scripts in {} ms", count, ElunaUtil::GetTimeDiff(oldMSTime));
OnLuaStateOpen(); OnLuaStateOpen();
} }
@@ -544,7 +544,7 @@ void Eluna::InvalidateObjects()
void Eluna::Report(lua_State* _L) void Eluna::Report(lua_State* _L)
{ {
const char* msg = lua_tostring(_L, -1); const char* msg = lua_tostring(_L, -1);
ELUNA_LOG_ERROR("%s", msg); ELUNA_LOG_ERROR("{}", msg);
lua_pop(_L, 1); lua_pop(_L, 1);
} }
@@ -589,7 +589,7 @@ bool Eluna::ExecuteCall(int params, int res)
// Check function type // Check function type
if (!lua_isfunction(L, base)) if (!lua_isfunction(L, base))
{ {
ELUNA_LOG_ERROR("[Eluna]: Cannot execute call: registered value is %s, not a function.", luaL_tolstring(L, base, NULL)); ELUNA_LOG_ERROR("[Eluna]: Cannot execute call: registered value is {}, not a function.", luaL_tolstring(L, base, NULL));
ASSERT(false); // stack probably corrupt ASSERT(false); // stack probably corrupt
} }