mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Refactor logging
- Add warning log level - Change debug_log_level setting to enumeration string - Map Irrlicht log events to MT log events - Encapsulate log_* functions and global variables into a class, Logger - Unify dstream with standard logging mechanism - Unify core.debug() with standard core.log() script API
This commit is contained in:
parent
e0b57c1140
commit
2139d7d45f
25 changed files with 599 additions and 652 deletions
|
@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "json/json.h"
|
||||
#include "cpp_api/s_security.h"
|
||||
#include "areastore.h"
|
||||
#include "debug.h"
|
||||
#include "porting.h"
|
||||
#include "log.h"
|
||||
#include "tool.h"
|
||||
|
@ -35,35 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/auth.h"
|
||||
#include <algorithm>
|
||||
|
||||
// debug(...)
|
||||
// Writes a line to dstream
|
||||
int ModApiUtil::l_debug(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
// Handle multiple parameters to behave like standard lua print()
|
||||
int n = lua_gettop(L);
|
||||
lua_getglobal(L, "tostring");
|
||||
for (int i = 1; i <= n; i++) {
|
||||
/*
|
||||
Call tostring(i-th argument).
|
||||
This is what print() does, and it behaves a bit
|
||||
differently from directly calling lua_tostring.
|
||||
*/
|
||||
lua_pushvalue(L, -1); /* function to be called */
|
||||
lua_pushvalue(L, i); /* value to print */
|
||||
lua_call(L, 1, 1);
|
||||
size_t len;
|
||||
const char *s = lua_tolstring(L, -1, &len);
|
||||
if (i > 1)
|
||||
dstream << "\t";
|
||||
if (s)
|
||||
dstream << std::string(s, len);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
dstream << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// log([level,] text)
|
||||
// Writes a line to the logger.
|
||||
// The one-argument version logs to infostream.
|
||||
|
@ -72,26 +42,24 @@ int ModApiUtil::l_log(lua_State *L)
|
|||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
std::string text;
|
||||
LogMessageLevel level = LMT_INFO;
|
||||
LogLevel level = LL_NONE;
|
||||
if (lua_isnone(L, 2)) {
|
||||
text = lua_tostring(L, 1);
|
||||
}
|
||||
else {
|
||||
std::string levelname = luaL_checkstring(L, 1);
|
||||
text = luaL_checkstring(L, 1);
|
||||
} else {
|
||||
std::string name = luaL_checkstring(L, 1);
|
||||
text = luaL_checkstring(L, 2);
|
||||
if(levelname == "error")
|
||||
level = LMT_ERROR;
|
||||
else if(levelname == "action")
|
||||
level = LMT_ACTION;
|
||||
else if(levelname == "verbose")
|
||||
level = LMT_VERBOSE;
|
||||
else if (levelname == "deprecated") {
|
||||
log_deprecated(L,text);
|
||||
if (name == "deprecated") {
|
||||
log_deprecated(L, text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
level = Logger::stringToLevel(name);
|
||||
if (level == LL_MAX) {
|
||||
warningstream << "Tried to log at unknown level '" << name
|
||||
<< "'. Defaulting to \"none\"." << std::endl;
|
||||
level = LL_NONE;
|
||||
}
|
||||
}
|
||||
log_printline(level, text);
|
||||
g_logger.log(level, text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -390,7 +358,6 @@ int ModApiUtil::l_request_insecure_environment(lua_State *L)
|
|||
|
||||
void ModApiUtil::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(debug);
|
||||
API_FCT(log);
|
||||
|
||||
API_FCT(setting_set);
|
||||
|
@ -422,7 +389,6 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
|||
|
||||
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
||||
{
|
||||
ASYNC_API_FCT(debug);
|
||||
ASYNC_API_FCT(log);
|
||||
|
||||
//ASYNC_API_FCT(setting_set);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue