From 2139d7d45fb1a8ed250ad96c9975c581f02f72a9 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Tue, 13 Oct 2015 03:57:44 -0400 Subject: 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 --- builtin/common/strict.lua | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'builtin/common') diff --git a/builtin/common/strict.lua b/builtin/common/strict.lua index c7b86461f..05ceadf7a 100644 --- a/builtin/common/strict.lua +++ b/builtin/common/strict.lua @@ -9,11 +9,6 @@ function core.global_exists(name) end -local function warn(message) - print(os.date("%H:%M:%S: WARNING: ")..message) -end - - local meta = {} local declared = {} -- Key is source file, line, and variable name; seperated by NULs @@ -27,7 +22,7 @@ function meta:__newindex(name, value) info.currentline, name) if not warned[warn_key] and info.what ~= "main" and info.what ~= "C" then - warn(("Assignment to undeclared ".. + core.log("warning", ("Assignment to undeclared ".. "global %q inside a function at %s.") :format(name, desc)) warned[warn_key] = true @@ -35,9 +30,8 @@ function meta:__newindex(name, value) declared[name] = true end -- Ignore mod namespaces - if WARN_INIT and (not core.get_current_modname or - name ~= core.get_current_modname()) then - warn(("Global variable %q created at %s.") + if WARN_INIT and name ~= core.get_current_modname() then + core.log("warning", ("Global variable %q created at %s.") :format(name, desc)) end rawset(self, name, value) @@ -48,7 +42,7 @@ function meta:__index(name) local info = debug.getinfo(2, "Sl") local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name) if not declared[name] and not warned[warn_key] and info.what ~= "C" then - warn(("Undeclared global variable %q accessed at %s:%s") + core.log("warning", ("Undeclared global variable %q accessed at %s:%s") :format(name, info.short_src, info.currentline)) warned[warn_key] = true end -- cgit v1.2.3