Improve log messages (#422)

- Add log messages wherever required/useful
- Remove unnecessary log messages and print statements
- Convert print statements to minetest.log
- Fix incorrect log level for some messages
- Trivial code-style fixes
This commit is contained in:
ANAND 2019-10-18 11:22:18 +05:30 committed by GitHub
parent 21e7daa183
commit 5eb5d3311a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 71 additions and 49 deletions

View file

@ -15,7 +15,7 @@ globals = {
"crafting", "vector", "table", "minetest", "worldedit", "ctf", "ctf_flag", "crafting", "vector", "table", "minetest", "worldedit", "ctf", "ctf_flag",
"ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map", "ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map",
"ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc", "ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc",
"armor", "armor", "vote", "give_initial_stuff"
} }
read_globals = { read_globals = {

View file

@ -50,8 +50,6 @@ function ctf_alloc.set_all()
return a.score > b.score return a.score > b.score
end) end)
minetest.log("warning", dump(players))
local to_red = math.random(2) == 2 local to_red = math.random(2) == 2
for _, spair in pairs(players) do for _, spair in pairs(players) do
local player = spair.player local player = spair.player

View file

@ -99,6 +99,7 @@ ctf.register_on_killedplayer(function(victim, killer)
bountied_player = nil bountied_player = nil
local msg = killer .. " has killed " .. victim .. " and received the prize!" local msg = killer .. " has killed " .. victim .. " and received the prize!"
minetest.log("action", msg)
minetest.chat_send_all(msg) minetest.chat_send_all(msg)
hud_score.new(killer, { hud_score.new(killer, {
name = "ctf_bounty:prize", name = "ctf_bounty:prize",
@ -118,6 +119,7 @@ minetest.register_chatcommand("place_bounty", {
end end
bounty_player(target) bounty_player(target)
minetest.log("action", name .. " places bounty on " .. target)
return true, "Put bounty on " .. target return true, "Put bounty on " .. target
end end
}) })

View file

@ -114,7 +114,7 @@ function ctf_map.place_outer_barrier(center, r, h)
minp.y = center.y - h / 2 minp.y = center.y - h / 2
maxp.y = center.y + h / 2 maxp.y = center.y + h / 2
print("Loading data into LVM") minetest.log("action", "Map maker: Loading data into LVM")
local vm = minetest.get_voxel_manip() local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(minp, maxp) local emin, emax = vm:read_from_map(minp, maxp)
@ -124,7 +124,7 @@ function ctf_map.place_outer_barrier(center, r, h)
} }
local data = vm:get_data() local data = vm:get_data()
print("Placing left wall") minetest.log("action", "Map maker: Placing left wall")
-- Left -- Left
do do
@ -141,7 +141,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Placing right wall") minetest.log("action", "Map maker: Placing right wall")
-- Right -- Right
do do
@ -158,7 +158,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Placing front wall") minetest.log("action", "Map maker: Placing front wall")
-- Front -- Front
do do
@ -175,7 +175,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Placing back wall") minetest.log("action", "Map maker: Placing back wall")
-- Back -- Back
do do
@ -192,7 +192,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Placing bedrock") minetest.log("action", "Map maker: Placing bedrock")
-- Bedrock -- Bedrock
do do
@ -204,7 +204,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Placing ceiling") minetest.log("action", "Map maker: Placing ceiling")
-- Ceiling -- Ceiling
do do
@ -216,7 +216,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end end
end end
print("Writing to engine!") minetest.log("action", "Map maker: Writing to engine!")
vm:set_data(data) vm:set_data(data)
vm:write_to_map(data) vm:write_to_map(data)

View file

@ -152,6 +152,7 @@ minetest.register_chatcommand("maps", {
send_irc_catalog(name, idx or 1) send_irc_catalog(name, idx or 1)
end end
minetest.log("action", name .. " views the map catalog")
return true return true
end end
}) })

View file

@ -72,6 +72,7 @@ minetest.register_chatcommand("set_next", {
local idx, map = ctf_map.get_idx_and_map(param) local idx, map = ctf_map.get_idx_and_map(param)
if idx then if idx then
next_idx = idx next_idx = idx
minetest.log("action", name .. " selected '" .. map.name .. "' as next map")
return true, "Selected " .. map.name return true, "Selected " .. map.name
else else
return false, "Couldn't find any matches" return false, "Couldn't find any matches"
@ -80,7 +81,7 @@ minetest.register_chatcommand("set_next", {
}) })
local function load_map_meta(idx, path) local function load_map_meta(idx, path)
print("load_map_meta: Loading map meta from \"" .. path .. "\"") minetest.log("info", "load_map_meta: Loading map meta from \"" .. path .. "\"")
local conf_path = mapdir .. path .. ".conf" local conf_path = mapdir .. path .. ".conf"
local offset = vector.new(600 * idx, 0, 0) local offset = vector.new(600 * idx, 0, 0)
local meta = Settings(conf_path) local meta = Settings(conf_path)
@ -137,6 +138,7 @@ local function load_map_meta(idx, path)
-- Read custom chest zones from config -- Read custom chest zones from config
i = 1 i = 1
minetest.log("info", "Parsing chest zones of " .. map.name .. "...")
while meta:get("chests." .. i .. ".from") do while meta:get("chests." .. i .. ".from") do
local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from")) local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from"))
local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to")) local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to"))
@ -149,7 +151,7 @@ local function load_map_meta(idx, path)
n = tonumber(meta:get("chests." .. i .. ".n") or "23"), n = tonumber(meta:get("chests." .. i .. ".n") or "23"),
} }
minetest.log("warning", dump(map.chests[i])) minetest.log("info", dump(map.chests[i]))
i = i + 1 i = i + 1
end end
@ -252,7 +254,7 @@ local function place_map(map)
local seed = minetest.get_mapgen_setting("seed") local seed = minetest.get_mapgen_setting("seed")
for _, chestzone in pairs(ctf_map.map.chests) do for _, chestzone in pairs(ctf_map.map.chests) do
minetest.log("warning", "Placing " .. chestzone.n .. " chests from " .. minetest.log("info", "Placing " .. chestzone.n .. " chests from " ..
minetest.pos_to_string(chestzone.from) .. " to ".. minetest.pos_to_string(chestzone.from) .. " to "..
minetest.pos_to_string(chestzone.to)) minetest.pos_to_string(chestzone.to))
place_chests(chestzone.from, chestzone.to, seed, chestzone.n) place_chests(chestzone.from, chestzone.to, seed, chestzone.n)
@ -340,7 +342,7 @@ ctf_match.register_on_new_match(function()
end end
if is_valid then if is_valid then
minetest.log("info", minetest.log("action",
"ctf_map: Registering treasure - " .. def[1]) "ctf_map: Registering treasure - " .. def[1])
treasurer.register_treasure(def[1], def[2], def[3], def[4]) treasurer.register_treasure(def[1], def[2], def[3], def[4])
end end
@ -362,7 +364,7 @@ function ctf_match.create_teams()
local flag = table.copy(value.pos) local flag = table.copy(value.pos)
if name and color and flag then if name and color and flag then
print(" - creating " .. key) minetest.log("action", "Creating team " .. key)
ctf.team({ ctf.team({
name = name, name = name,
color = color, color = color,
@ -375,7 +377,7 @@ function ctf_match.create_teams()
ctf_flag.assert_flag(flag) ctf_flag.assert_flag(flag)
end) end)
else else
minetest.log("error", " - Failed to create " .. key) minetest.log("error", "Failed to create team " .. key)
end end
end end
end end

View file

@ -47,6 +47,8 @@ local function add_marker(name, tname, pos, str)
world_pos = pos world_pos = pos
}) })
end end
minetest.log("action", name .. " placed a marker at " ..
minetest.pos_to_string(pos) .. ": '" .. str .. "'")
minetest.chat_send_player(pname, minetest.chat_send_player(pname,
msg("Player " .. name .. " placed a marker!")) msg("Player " .. name .. " placed a marker!"))
end end

View file

@ -9,6 +9,7 @@ minetest.register_chatcommand("ctf_next", {
}, },
func = function(name, param) func = function(name, param)
ctf_match.next() ctf_match.next()
minetest.log("action", name .. " ran /ctf_next")
end end
}) })
@ -19,6 +20,7 @@ minetest.register_chatcommand("ctf_start", {
}, },
func = function(name, param) func = function(name, param)
ctf_match.build_timer = 0.01 ctf_match.build_timer = 0.01
minetest.log("action", name .. " ran /ctf_start")
end end
}) })
@ -58,6 +60,7 @@ minetest.register_chatcommand("ctf_queue_restart", {
func = function(name, param) func = function(name, param)
restart_on_next_match = true restart_on_next_match = true
restart_on_next_match_by = name restart_on_next_match_by = name
minetest.log("action", name .. " queued a restart")
return true, "Restart queued." return true, "Restart queued."
end end
}) })
@ -69,6 +72,7 @@ minetest.register_chatcommand("ctf_unqueue_restart", {
}, },
func = function(name, param) func = function(name, param)
restart_on_next_match = false restart_on_next_match = false
minetest.log("action", name .. " un-queued a restart")
return true, "Restart cancelled." return true, "Restart cancelled."
end end
}) })

View file

@ -54,7 +54,6 @@ local function update(player, settings)
if settings.type == TYPE_BUILTIN then if settings.type == TYPE_BUILTIN then
remove_entity_tag(player) remove_entity_tag(player)
print(dump(settings.color))
player:set_nametag_attributes({ player:set_nametag_attributes({
color = settings.color color = settings.color
}) })

View file

@ -287,11 +287,13 @@ minetest.register_chatcommand("r", {
param = param:trim() param = param:trim()
if ctf_stats.players[param] then if ctf_stats.players[param] then
target = param target = param
minetest.log("action", name .. " ran /r " .. param)
else else
return false, "Can't find player '" .. param .. "'" return false, "Can't find player '" .. param .. "'"
end end
else else
target = name target = name
minetest.log("action", name .. " ran /r")
end end
return return_as_chat_result(name, target) return return_as_chat_result(name, target)
end end
@ -306,11 +308,13 @@ minetest.register_chatcommand("rankings", {
param = param:trim() param = param:trim()
if ctf_stats.players[param] then if ctf_stats.players[param] then
target = param target = param
minetest.log("action", name .. " ran /rankings " .. param)
else else
return false, "Can't find player '" .. param .. "'" return false, "Can't find player '" .. param .. "'"
end end
else else
target = name target = name
minetest.log("action", name .. " ran /rankings")
end end
if not minetest.get_player_by_name(name) then if not minetest.get_player_by_name(name) then
@ -359,6 +363,13 @@ minetest.register_chatcommand("reset_rankings", {
ctf_stats.players[reset_name] = nil ctf_stats.players[reset_name] = nil
ctf_stats.player(reset_name) ctf_stats.player(reset_name)
if reset_name == name then
minetest.log("action", name .. " reset their rankings")
else
minetest.log("action", name .. " reset rankings of " .. reset_name)
end
return true, "Successfully reset the stats and ranking of " .. reset_name return true, "Successfully reset the stats and ranking of " .. reset_name
end end
}) })
@ -386,6 +397,7 @@ minetest.register_chatcommand("transfer_rankings", {
ctf_stats.players[dest] = ctf_stats.players[src] ctf_stats.players[dest] = ctf_stats.players[src]
ctf_stats.players[src] = nil ctf_stats.players[src] = nil
minetest.log("action", name .. " transferred stats of " .. src .. " to " .. dest)
return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'." return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'."
end end
}) })

View file

@ -350,6 +350,7 @@ minetest.register_chatcommand("summary", {
fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]" fs = fs .. "button[6,7.5;4,1;b_prev;<< Previous match]"
minetest.log("action", name .. " requested match summary formspec")
minetest.show_formspec(name, "ctf_stats:match_summary", fs) minetest.show_formspec(name, "ctf_stats:match_summary", fs)
end end
}) })

View file

@ -3,6 +3,7 @@ minetest.register_chatcommand("killme", {
func = function(name) func = function(name)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if player then if player then
minetest.log("action", name .. " ran /killme")
if minetest.settings:get_bool("enable_damage") then if minetest.settings:get_bool("enable_damage") then
player:set_hp(0) player:set_hp(0)
return true return true

View file

@ -11,6 +11,7 @@ local function add_irc_mod(name)
end end
mods[#mods + 1] = name mods[#mods + 1] = name
storage:set_string("irc_mods", table.concat(mods, ",")) storage:set_string("irc_mods", table.concat(mods, ","))
minetest.log("action", name .. " subscribed to IRC reports")
return true return true
end end
@ -20,6 +21,7 @@ local function remove_irc_mod(name)
if idx > 0 then if idx > 0 then
table.remove(mods, idx) table.remove(mods, idx)
storage:set_string("irc_mods", table.concat(mods, ",")) storage:set_string("irc_mods", table.concat(mods, ","))
minetest.log("action", name .. " un-subscribed from IRC reports")
return true return true
end end
return false return false
@ -36,6 +38,7 @@ minetest.register_chatcommand("report_sub", {
end end
else else
if add_irc_mod(name) then if add_irc_mod(name) then
minetest.log("action", name .. " subscribed to IRC reports")
return true, "Successfully added!" return true, "Successfully added!"
else else
return false, "Unable to add, are you already subscribed?" return false, "Unable to add, are you already subscribed?"

View file

@ -203,14 +203,14 @@ function place_chests(minp, maxp, seed, number_chests)
chest_pos.z = -1 chest_pos.z = -1
end end
local nn = minetest.get_node(chest_pos).name -- chest node name (before it becomes a chest) -- chest node name (before it becomes a chest)
local nn = minetest.get_node(chest_pos).name
if nn == "air" or nn == "default:water_source" then if nn == "air" or nn == "default:water_source" then
placeChest(pos, chest_pos, ground, nn) placeChest(pos, chest_pos, ground, nn)
chests_placed = chests_placed + 1 chests_placed = chests_placed + 1
end end
end end
end end
minetest.log("warning", "Spawned " .. chests_placed .. "/" .. number_chests .. " chests after " .. attempts .. " attempts!") minetest.log("info", "Spawned " .. chests_placed .. "/" .. number_chests .. " chests after " .. attempts .. " attempts!")
end end

View file

@ -34,7 +34,7 @@ function vote.start_vote(voteset)
if voteset.options then if voteset.options then
for _, option in pairs(voteset.options) do for _, option in pairs(voteset.options) do
voteset.results[option] = {} voteset.results[option] = {}
print(" - " .. option) minetest.log("action", " - " .. option)
end end
else else
voteset.results.yes = {} voteset.results.yes = {}

View file

@ -2,19 +2,19 @@ vote.kick_cooldown = 600
local vlist = {} -- table storing player name, ip & lock status local vlist = {} -- table storing player name, ip & lock status
minetest.register_privilege("vote_kick", { minetest.register_privilege("vote_kick", {
description = "Can (start) vote to kick a player", description = "Can start vote to kick a player",
on_grant = function(name, granter) on_grant = function(name, granter)
if not granter then if not granter then
granter = "<nil>" granter = "<nil>"
end end
minetest.log("warning", "Player '" .. name .. "' has been" .. minetest.log("action", "Player '" .. name .. "' has been" ..
" granted 'vote_kick' by '" .. granter .. "'") " granted 'vote_kick' by '" .. granter .. "'")
end, end,
on_revoke = function(name, revoker) on_revoke = function(name, revoker)
if not revoker then if not revoker then
revoker = "<nil>" revoker = "<nil>"
end end
minetest.log("warning", "Player '" .. name .. "' has been" .. minetest.log("action", "Player '" .. name .. "' has been" ..
" revoked of 'vote_kick' by '" .. revoker .. "'") " revoked of 'vote_kick' by '" .. revoker .. "'")
end end
}) })
@ -33,17 +33,14 @@ minetest.register_chatcommand("vote_kick", {
end end
if not minetest.get_player_by_name(param) then if not minetest.get_player_by_name(param) then
return false, "There is no player called '" .. return false, "There is no player called '" .. param .. "'"
param .. "'"
end end
if minetest.check_player_privs(param, {kick = true, ban = true}) then if minetest.check_player_privs(param, {kick = true, ban = true}) then
return false, param .. " is a moderator, and can't be kicked!" return false, param .. " is a moderator, and can't be kicked!"
end end
minetest.log("warning", "Player '" .. name .. "' started a vote" .. minetest.log("action", name .. " started a vote to kick " .. param)
" to kick '" .. param .. "'")
if not vlist[param] then if not vlist[param] then
vlist[param] = { vlist[param] = {
@ -108,6 +105,7 @@ minetest.register_chatcommand("unblock", {
end end
vlist[param].locked = false vlist[param].locked = false
minetest.log("action", name .. " unblocked " .. param .. ", who was vote-kicked")
return true, param .. " has been successfully unblocked!" return true, param .. " has been successfully unblocked!"
end end
}) })

View file

@ -6,7 +6,7 @@ local function drop(pos, itemstack)
for _, item in pairs(blacklist_drop) do for _, item in pairs(blacklist_drop) do
if sname == item then if sname == item then
minetest.log("info", "Not dropping " .. item) minetest.log("info", "[dropondie] Not dropping " .. sname)
return return
end end
end end
@ -20,7 +20,6 @@ local function drop(pos, itemstack)
if minetest.is_yes(remi) then if minetest.is_yes(remi) then
obj:remove() obj:remove()
end end
end end
return itemstack return itemstack
end end

View file

@ -22,13 +22,13 @@ end
function hp_bar:on_step(dtime) function hp_bar:on_step(dtime)
local wielder = self.wielder and minetest.get_player_by_name(self.wielder) local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
if wielder == nil then if wielder == nil then
print("[gauges] Gauge removed as null wielder! " .. dump(self.wielder)) minetest.log("warning", "[gauges] Gauge removed as null wielder! " .. dump(self.wielder))
self.object:remove() self.object:remove()
return return
end end
if vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3 then if vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3 then
print("[gauges] Gauge removed as not attached! " .. dump(self.wielder)) minetest.log("warning", "[gauges] Gauge removed as not attached! " .. dump(self.wielder))
self.object:remove() self.object:remove()
return return
end end
@ -80,7 +80,7 @@ function gauges.check_gauges()
end end
if not found then if not found then
print("Gauge not found!") minetest.log("warning", "[gauges] Gauge not found for player " .. pname)
gauges.add_HP_gauge(pname) gauges.add_HP_gauge(pname)
end end
end end