Validate log message levels

This commit is contained in:
Aaron Suen 2020-06-09 19:02:07 -04:00
parent a998009656
commit 6c640a11b1
14 changed files with 23 additions and 17 deletions

View File

@ -20,7 +20,7 @@ function nodecore.digparticles(nodedef, partdef)
elseif nodedef.inventory_image then elseif nodedef.inventory_image then
img[1] = nodedef.inventory_image img[1] = nodedef.inventory_image
end end
if #img < 1 then return minetest.log("error", "no pummel tile images found!") end if #img < 1 then return nodecore.log("error", "no pummel tile images found!") end
img = nodecore.pickrand(img) img = nodecore.pickrand(img)
if img.name then img = img.name end if img.name then img = img.name end

View File

@ -1,9 +1,9 @@
-- LUALOCALS < --------------------------------------------------------- -- LUALOCALS < ---------------------------------------------------------
-- SKIP: include nodecore -- SKIP: include nodecore
local dofile, error, minetest, pairs, rawget, rawset, setmetatable, local dofile, error, minetest, pairs, rawget, rawset, setmetatable,
table, type table, tostring, type
= dofile, error, minetest, pairs, rawget, rawset, setmetatable, = dofile, error, minetest, pairs, rawget, rawset, setmetatable,
table, type table, tostring, type
local table_concat, table_insert local table_concat, table_insert
= table.concat, table.insert = table.concat, table.insert
-- LUALOCALS > --------------------------------------------------------- -- LUALOCALS > ---------------------------------------------------------
@ -52,6 +52,12 @@ minetest.register_on_mods_loaded(function()
end end
end) end)
local levels = {none = true, error = true, warning = true, action = true, info = true, verbose = true}
function nodecore.log(level, ...)
if not level or not levels[level] then error("invalid log level " .. tostring(level)) end
return minetest.log(level, ...)
end
include("compat_vector") include("compat_vector")
include("issue9043") include("issue9043")

View File

@ -12,7 +12,7 @@ minetest.after(0, function()
for k in pairs(missing) do t[#t + 1] = k end for k in pairs(missing) do t[#t + 1] = k end
if #t < 1 then return end if #t < 1 then return end
table_sort(t) table_sort(t)
minetest.log("warning", "WARNING: missing txp override images:\n\t" nodecore.log("warning", "WARNING: missing txp override images:\n\t"
.. table_concat(t, "\n\t")) .. table_concat(t, "\n\t"))
end) end)

View File

@ -14,5 +14,5 @@ local limitchunks = math_floor(limit / chunksize)
nodecore.map_limit_min = (-limitchunks + 0.5) * chunksize + 7.5 nodecore.map_limit_min = (-limitchunks + 0.5) * chunksize + 7.5
nodecore.map_limit_max = (limitchunks - 0.5) * chunksize + 7.5 nodecore.map_limit_max = (limitchunks - 0.5) * chunksize + 7.5
minetest.log("info", string_format("mapgen limit: %d, chunk: %d, bounds: %0.1f to %0.1f", nodecore.log("info", string_format("mapgen limit: %d, chunk: %d, bounds: %0.1f to %0.1f",
limit, chunksize, nodecore.map_limit_min, nodecore.map_limit_max)) limit, chunksize, nodecore.map_limit_min, nodecore.map_limit_max))

View File

@ -9,12 +9,12 @@ minetest.register_globalstep(function(dtime)
local mtt = minetest.get_gametime() local mtt = minetest.get_gametime()
local nct = nodecore.gametime local nct = nodecore.gametime
if not nct then if not nct then
minetest.log("info", "nodecore.gametime: init to " .. mtt) nodecore.log("info", "nodecore.gametime: init to " .. mtt)
nct = mtt nct = mtt
end end
nct = nct + dtime nct = nct + dtime
if math_abs(nct - mtt) >= 2 then if math_abs(nct - mtt) >= 2 then
minetest.log("info", "nodecore.gametime: excess drift; nct=" nodecore.log("info", "nodecore.gametime: excess drift; nct="
.. nct .. ", mtt=" .. mtt) .. nct .. ", mtt=" .. mtt)
nct = mtt nct = mtt
end end

View File

@ -310,7 +310,7 @@ function nodecore.node_spin_custom(...)
node = node or minetest.get_node(pos) node = node or minetest.get_node(pos)
node.param2 = lut[node.param2] or lut[false] node.param2 = lut[node.param2] or lut[false]
if clicker:is_player() then if clicker:is_player() then
minetest.log("action", clicker:get_player_name() .. " spins " nodecore.log("action", clicker:get_player_name() .. " spins "
.. node.name .. " at " .. minetest.pos_to_string(pos) .. node.name .. " at " .. minetest.pos_to_string(pos)
.. " to param2 " .. node.param2 .. " (" .. " to param2 " .. node.param2 .. " ("
.. qty .. " total)") .. qty .. " total)")

View File

@ -49,7 +49,7 @@ minetest.after(0, function()
defs = defs + n defs = defs + n
if n > peak then peak = n end if n > peak then peak = n end
end end
minetest.log("info", string_format("register_aism: %d keys, %d defs, %d peak", keys, defs, peak)) nodecore.log("info", string_format("register_aism: %d keys, %d defs, %d peak", keys, defs, peak))
end) end)
local function checkrun(def, stack, data) local function checkrun(def, stack, data)

View File

@ -10,7 +10,7 @@ local pumpbatch = {}
minetest.register_globalstep(function() minetest.register_globalstep(function()
for def in pairs(pumpbatch) do for def in pairs(pumpbatch) do
if def.limited_qty >= def.limited_alert then if def.limited_qty >= def.limited_alert then
minetest.log("warning", "limited abm \"" .. def.label .. "\" filled (" nodecore.log("warning", "limited abm \"" .. def.label .. "\" filled ("
.. def.limited_qty .. "/" .. def.limited_max .. ")") .. def.limited_qty .. "/" .. def.limited_max .. ")")
end end

View File

@ -137,7 +137,7 @@ local function craftcheck(recipe, pos, node, data, xx, xz, zx, zz)
function(p) return lut[minetest.hash_node_position(p)] end function(p) return lut[minetest.hash_node_position(p)] end
) )
end end
minetest.log("action", (data.crafter and data.crafter:get_player_name() or "unknown") nodecore.log("action", (data.crafter and data.crafter:get_player_name() or "unknown")
.. " completed recipe \"" .. recipe.label .. "\" at " .. .. " completed recipe \"" .. recipe.label .. "\" at " ..
minetest.pos_to_string(pos) .. " upon " .. node.name) minetest.pos_to_string(pos) .. " upon " .. node.name)
return true return true

View File

@ -52,7 +52,7 @@ end
tryhook() tryhook()
function nodecore.ent_prop_set(obj, def) function nodecore.ent_prop_set(obj, def)
minetest.log("warning", "WARNING: nodecore.ent_prop_set() is now deprecated;" nodecore.log("warning", "WARNING: nodecore.ent_prop_set() is now deprecated;"
.. " just use object:set_properties(), which has been patched") .. " just use object:set_properties(), which has been patched")
return obj:set_properties(def) return obj:set_properties(def)
end end

View File

@ -50,7 +50,7 @@ local function handlepickups(player)
v = nodecore.stack_merge(snap[j], v) v = nodecore.stack_merge(snap[j], v)
end end
if not v:is_empty() then if not v:is_empty() then
minetest.log("error", "failed to reinsert item " nodecore.log("error", "failed to reinsert item "
.. v:get_name() .. " " .. v:get_count() .. v:get_name() .. " " .. v:get_count()
.. " for " .. pname) .. " for " .. pname)
dirty = nil dirty = nil
@ -67,7 +67,7 @@ local function handlepickups(player)
end end
if dirty then if dirty then
minetest.log("info", "inventory rearranged for " .. pname) nodecore.log("info", "inventory rearranged for " .. pname)
inv:set_list("main", snap) inv:set_list("main", snap)
end end
end end

View File

@ -75,7 +75,7 @@ local function playeradd(qty, player, ...)
end end
if qty ~= 0 and dbadd(qty, pname, ...) <= qty then if qty ~= 0 and dbadd(qty, pname, ...) <= qty then
local t = {...} local t = {...}
minetest.log("action", string_format("player %q discovered %q", nodecore.log("action", string_format("player %q discovered %q",
pname, table_concat(t, ":"))) pname, table_concat(t, ":")))
for _, v in pairs(nodecore.registered_on_player_discovers) do for _, v in pairs(nodecore.registered_on_player_discovers) do
v(player, t) v(player, t)

View File

@ -36,7 +36,7 @@ minetest.register_node(modname .. ":eggcorn", {
if nodecore.player_stat_add then if nodecore.player_stat_add then
nodecore.player_stat_add(1, whom, "craft", "eggcorn planting") nodecore.player_stat_add(1, whom, "craft", "eggcorn planting")
end end
minetest.log("action", (whom and whom:get_player_name() or "unknown") nodecore.log("action", (whom and whom:get_player_name() or "unknown")
.. " planted an eggcorn at " .. minetest.pos_to_string(pos)) .. " planted an eggcorn at " .. minetest.pos_to_string(pos))
stack:set_count(stack:get_count() - 1) stack:set_count(stack:get_count() - 1)

View File

@ -52,7 +52,7 @@ end
local function matching(pa, na, pb, nb) local function matching(pa, na, pb, nb)
if stackonly[na.name] then if stackonly[na.name] then
if not stackonly[nb.name] then return end if not stackonly[nb.name] then return end
minetest.log("info", nodecore.stack_get(pa):get_name() .. " ?= " nodecore.log("info", nodecore.stack_get(pa):get_name() .. " ?= "
.. nodecore.stack_get(pb):get_name()) .. nodecore.stack_get(pb):get_name())
return (laststack and laststack:get_name()) == nodecore.stack_get(pb):get_name() return (laststack and laststack:get_name()) == nodecore.stack_get(pb):get_name()
end end