aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-10-13 03:57:44 -0400
committerkwolekr <kwolekr@minetest.net>2015-10-14 01:03:54 -0400
commit2139d7d45fb1a8ed250ad96c9975c581f02f72a9 (patch)
tree3e954063710add83723798937637db7c67a254eb /src/script/lua_api
parente0b57c1140554fccbf3e57a036cc4100887ab8f1 (diff)
downloadminetest-2139d7d45fb1a8ed250ad96c9975c581f02f72a9.tar.gz
minetest-2139d7d45fb1a8ed250ad96c9975c581f02f72a9.tar.bz2
minetest-2139d7d45fb1a8ed250ad96c9975c581f02f72a9.zip
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
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_util.cpp60
-rw-r--r--src/script/lua_api/l_util.h4
2 files changed, 13 insertions, 51 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 4b8b6d351..a4f01af07 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -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);
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index e75aa28cb..4b55b1966 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -35,10 +35,6 @@ private:
GUIEngine instance should be in here.
*/
- // debug(text)
- // Writes a line to dstream
- static int l_debug(lua_State *L);
-
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.