Cleanup logging

This commit is contained in:
Jordan Irwin 2021-05-05 19:11:14 -07:00
parent 2603c721d2
commit 428b88bdda
3 changed files with 32 additions and 27 deletions

@ -1,27 +1,10 @@
-- Functions for sneeker mod
local log_mods = core.settings:get_bool("log_mods", false)
-- Displays a message in log output
function sneeker.log(message)
if log_mods then
core.log('action', '[' .. sneeker.modname .. '] ' .. message)
end
end
-- Displays a message in log output only if 'sneeker.debug' is set to 'true'
function sneeker.log_debug(message)
if sneeker.debug then
sneeker.log('DEBUG: ' .. message)
end
end
-- Spawns a sneeker entity
function sneeker.spawn(pos)
core.add_entity(pos, sneeker.mob_name)
sneeker.log_debug('Spawned entity "' .. sneeker.mob_name .. '" at ' .. tostring(pos.x) .. ',' .. tostring(pos.y))
sneeker.log("debug", "Spawned entity \"" .. sneeker.mob_name .. "\" at " .. tostring(pos.x) .. "," .. tostring(pos.y))
end
-- Retrieves pos coordinates in string value

@ -5,14 +5,36 @@ sneeker = {}
sneeker.modname = core.get_current_modname()
sneeker.modpath = core.get_modpath(sneeker.modname)
dofile(sneeker.modpath .. "/settings.lua")
sneeker.log = function(lvl, msg)
if lvl == "debug" and not sneeker.debug then return end
if not msg then
msg = lvl
lvl = nil
end
msg = "[" .. sneeker.modname .. "] " .. msg
if lvl == "debug" then
msg = "[DEBUG] " .. msg
end
if not lvl then
core.log(msg)
else
core.log(lvl, msg)
end
end
if core.settings:get_bool("log_mods", false) then
core.log("action", "Loading mod \"" .. sneeker.modname .. "\" ...")
end
dofile(sneeker.modpath .. "/settings.lua")
dofile(sneeker.modpath .. "/functions.lua")
sneeker.log_debug("Debugging is on")
sneeker.log("debug", "Debugging is on")
sneeker.mob_name = sneeker.modname .. ":" .. sneeker.modname
sneeker.spawnegg_name = sneeker.modname .. ":spawnegg"

@ -46,23 +46,23 @@ core.register_abm({
local node_light = core.get_node_light(pos)
-- Debugging spawning
sneeker.log_debug("Node light level at " .. sneeker.get_pos_string(pos) .. ": " .. tostring(node_light))
sneeker.log("debug", "Node light level at " .. sneeker.get_pos_string(pos) .. ": " .. tostring(node_light))
-- Node light level
if not node_light or node_light > spawn_maxlight then
sneeker.log_debug("Node not dark enough for spawn")
sneeker.log("debug", "Node not dark enough for spawn")
return
elseif node_light < spawn_minlight then
sneeker.log_debug("Node too dark for spawn")
sneeker.log("debug", "Node too dark for spawn")
return
end
-- Spawn range
if spawn_minheight ~= nil and pos.y < spawn_minheight then
sneeker.log_debug("Position is too low for spawn")
sneeker.log("debug", "Position is too low for spawn")
return
elseif pos.y > spawn_maxheight then
sneeker.log_debug("Position is too high for spawn")
sneeker.log("debug", "Position is too high for spawn")
return
end
@ -83,10 +83,10 @@ core.register_abm({
end
end
sneeker.log_debug("Current active spawns: " .. tostring(count) .. "/" .. tostring(spawn_cap))
sneeker.log("debug", "Current active spawns: " .. tostring(count) .. "/" .. tostring(spawn_cap))
if count >= spawn_cap then
sneeker.log_debug("Max spawns reached")
sneeker.log("debug", "Max spawns reached")
return
end