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",
"ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map",
"ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc",
"armor",
"armor", "vote", "give_initial_stuff"
}
read_globals = {

View file

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

View file

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

View file

@ -114,7 +114,7 @@ function ctf_map.place_outer_barrier(center, r, h)
minp.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 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()
print("Placing left wall")
minetest.log("action", "Map maker: Placing left wall")
-- Left
do
@ -141,7 +141,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Placing right wall")
minetest.log("action", "Map maker: Placing right wall")
-- Right
do
@ -158,7 +158,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Placing front wall")
minetest.log("action", "Map maker: Placing front wall")
-- Front
do
@ -175,7 +175,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Placing back wall")
minetest.log("action", "Map maker: Placing back wall")
-- Back
do
@ -192,7 +192,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Placing bedrock")
minetest.log("action", "Map maker: Placing bedrock")
-- Bedrock
do
@ -204,7 +204,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Placing ceiling")
minetest.log("action", "Map maker: Placing ceiling")
-- Ceiling
do
@ -216,7 +216,7 @@ function ctf_map.place_outer_barrier(center, r, h)
end
end
print("Writing to engine!")
minetest.log("action", "Map maker: Writing to engine!")
vm:set_data(data)
vm:write_to_map(data)

View file

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

View file

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

View file

@ -42,11 +42,13 @@ local function add_marker(name, tname, pos, str)
if tplayer then
teams[tname].players[pname] = tplayer:hud_add({
hud_elem_type = "waypoint",
name = str,
number = ctf.flag_colors[team.data.color],
world_pos = pos
name = str,
number = ctf.flag_colors[team.data.color],
world_pos = pos
})
end
minetest.log("action", name .. " placed a marker at " ..
minetest.pos_to_string(pos) .. ": '" .. str .. "'")
minetest.chat_send_player(pname,
msg("Player " .. name .. " placed a marker!"))
end
@ -68,7 +70,7 @@ end)
minetest.register_chatcommand("m", {
param = "[Optional description]",
description = "Allows players to share the location of where " ..
"they're looking at with their team-mates.",
"they're looking at with their team-mates.",
privs = { interact = true },
func = function(name, param)
local player = minetest.get_player_by_name(name)
@ -79,7 +81,7 @@ minetest.register_chatcommand("m", {
-- Calculate marker pos
local dir = player:get_look_dir()
local p1 = vector.add(player:get_pos(),
{ x = 0, y = player:get_properties().eye_height, z = 0})
{ x = 0, y = player:get_properties().eye_height, z = 0 })
p1 = vector.add(p1, dir)
local p2 = vector.add(p1, vector.multiply(dir, 500))
local pointed = minetest.raycast(p1, p2, true, true):next()

View file

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

View file

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

View file

@ -287,11 +287,13 @@ minetest.register_chatcommand("r", {
param = param:trim()
if ctf_stats.players[param] then
target = param
minetest.log("action", name .. " ran /r " .. param)
else
return false, "Can't find player '" .. param .. "'"
end
else
target = name
minetest.log("action", name .. " ran /r")
end
return return_as_chat_result(name, target)
end
@ -306,11 +308,13 @@ minetest.register_chatcommand("rankings", {
param = param:trim()
if ctf_stats.players[param] then
target = param
minetest.log("action", name .. " ran /rankings " .. param)
else
return false, "Can't find player '" .. param .. "'"
end
else
target = name
minetest.log("action", name .. " ran /rankings")
end
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.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
end
})
@ -386,6 +397,7 @@ minetest.register_chatcommand("transfer_rankings", {
ctf_stats.players[dest] = ctf_stats.players[src]
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 .. "'."
end
})

View file

@ -346,10 +346,11 @@ end)
minetest.register_chatcommand("summary", {
func = function(name)
local fs = ctf_stats.get_formspec_match_summary(ctf_stats.current,
winner_team, winner_player, os.time() - ctf_stats.start)
winner_team, winner_player, os.time() - ctf_stats.start)
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)
end
})

View file

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

View file

@ -11,6 +11,7 @@ local function add_irc_mod(name)
end
mods[#mods + 1] = name
storage:set_string("irc_mods", table.concat(mods, ","))
minetest.log("action", name .. " subscribed to IRC reports")
return true
end
@ -20,6 +21,7 @@ local function remove_irc_mod(name)
if idx > 0 then
table.remove(mods, idx)
storage:set_string("irc_mods", table.concat(mods, ","))
minetest.log("action", name .. " un-subscribed from IRC reports")
return true
end
return false
@ -36,6 +38,7 @@ minetest.register_chatcommand("report_sub", {
end
else
if add_irc_mod(name) then
minetest.log("action", name .. " subscribed to IRC reports")
return true, "Successfully added!"
else
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
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
placeChest(pos, chest_pos, ground, nn)
chests_placed = chests_placed + 1
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

View file

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

View file

@ -2,20 +2,20 @@ vote.kick_cooldown = 600
local vlist = {} -- table storing player name, ip & lock status
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)
if not granter then
granter = "<nil>"
end
minetest.log("warning", "Player '" .. name .. "' has been" ..
" granted 'vote_kick' by '" .. granter .. "'")
minetest.log("action", "Player '" .. name .. "' has been" ..
" granted 'vote_kick' by '" .. granter .. "'")
end,
on_revoke = function(name, revoker)
if not revoker then
revoker = "<nil>"
end
minetest.log("warning", "Player '" .. name .. "' has been" ..
" revoked of 'vote_kick' by '" .. revoker .. "'")
minetest.log("action", "Player '" .. name .. "' has been" ..
" revoked of 'vote_kick' by '" .. revoker .. "'")
end
})
@ -33,17 +33,14 @@ minetest.register_chatcommand("vote_kick", {
end
if not minetest.get_player_by_name(param) then
return false, "There is no player called '" ..
param .. "'"
return false, "There is no player called '" .. param .. "'"
end
if minetest.check_player_privs(param, {kick = true, ban = true}) then
return false, param .. " is a moderator, and can't be kicked!"
end
minetest.log("warning", "Player '" .. name .. "' started a vote" ..
" to kick '" .. param .. "'")
minetest.log("action", name .. " started a vote to kick " .. param)
if not vlist[param] then
vlist[param] = {
@ -69,8 +66,8 @@ minetest.register_chatcommand("vote_kick", {
#results.yes .. " to " .. #results.no .. ", " ..
self.name .. " will be kicked.")
minetest.kick_player(self.name,
("The vote to kick you passed.\n You have been temporarily banned" ..
" for %s minutes."):format(tostring(vote.kick_cooldown / 60)))
("The vote to kick you passed.\n You have been temporarily banned" ..
" for %s minutes."):format(tostring(vote.kick_cooldown / 60)))
vlist[self.name].locked = true
minetest.after(vote.kick_cooldown, function()
vlist[self.name] = nil
@ -108,6 +105,7 @@ minetest.register_chatcommand("unblock", {
end
vlist[param].locked = false
minetest.log("action", name .. " unblocked " .. param .. ", who was vote-kicked")
return true, param .. " has been successfully unblocked!"
end
})
@ -118,8 +116,8 @@ minetest.register_on_prejoinplayer(function(name, ip)
else
for k, v in pairs(vlist) do
if v.ip == ip and v.locked then
return "This IP has been temporarily blocked."..
" Please wait until the cool-down period has elapsed before rejoining."
return "This IP has been temporarily blocked." ..
" Please wait until the cool-down period has elapsed before rejoining."
end
end
end

View file

@ -6,7 +6,7 @@ local function drop(pos, itemstack)
for _, item in pairs(blacklist_drop) do
if sname == item then
minetest.log("info", "Not dropping " .. item)
minetest.log("info", "[dropondie] Not dropping " .. sname)
return
end
end
@ -14,13 +14,12 @@ local function drop(pos, itemstack)
local obj = minetest.add_item(pos, it)
if obj then
obj:set_velocity({x=math.random(-1,1), y=5, z=math.random(-1,1)})
obj:set_velocity({ x = math.random(-1, 1), y = 5, z = math.random(-1, 1) })
local remi = minetest.settings:get("remove_items")
if minetest.is_yes(remi) then
obj:remove()
end
end
return itemstack
end

View file

@ -22,13 +22,13 @@ end
function hp_bar:on_step(dtime)
local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
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()
return
end
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()
return
end
@ -80,7 +80,7 @@ function gauges.check_gauges()
end
if not found then
print("Gauge not found!")
minetest.log("warning", "[gauges] Gauge not found for player " .. pname)
gauges.add_HP_gauge(pname)
end
end