added prefix [MOD] yl_speak_up to debug.txt entries

This commit is contained in:
Sokomine 2022-09-10 00:50:43 +02:00
parent 940768de19
commit f514acd3bc
2 changed files with 26 additions and 28 deletions

View File

@ -2,7 +2,7 @@
-- log changes done by players or admins to NPCs -- log changes done by players or admins to NPCs
yl_speak_up.log_change = function(pname, n_id, text) yl_speak_up.log_change = function(pname, n_id, text, log_level)
-- make sure all variables are defined -- make sure all variables are defined
if(not(pname)) then if(not(pname)) then
pname = "- unkown player -" pname = "- unkown player -"
@ -13,32 +13,38 @@ yl_speak_up.log_change = function(pname, n_id, text)
if(not(text)) then if(not(text)) then
text = "- no text given -" text = "- no text given -"
end end
if(not(log_level)) then
log_level = "info"
end
-- we don't want newlines in the texts -- we don't want newlines in the texts
text = string.gsub(text, "\n", "\\n") text = string.gsub(text, "\n", "\\n")
-- log in debug.txt -- log in debug.txt
local log_text = "<"..tostring(n_id).."> ["..tostring(pname).."]: "..text local log_text = "<"..tostring(n_id).."> ["..tostring(pname).."]: "..text
minetest.log("yl_speak_up "..log_text) minetest.log(log_level, "[MOD] yl_speak_up "..log_text)
-- log in a file for each npc so that it can be shown when needed -- log in a file for each npc so that it can be shown when needed
-- date needs to be inserted manually (minetest.log does it automaticly); -- date needs to be inserted manually (minetest.log does it automaticly);
-- each file logs just one npc, so n_id is not important -- each file logs just one npc, so n_id is not important
log_text = tostring(os.date("%Y-%m-%d %H:%M:%S ")..tostring(pname).." "..text.."\n") log_text = tostring(os.date("%Y-%m-%d %H:%M:%S ")..tostring(pname).." "..text.."\n")
-- actually append to the logfile n_id = tostring(n_id)
local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM.. if(n_id and n_id ~= "" and n_id ~= "n_" and n_id ~= "- unkown NPC -") then
-- actually append to the logfile
local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM..
"log_"..tostring(n_id)..".txt", "a") "log_"..tostring(n_id)..".txt", "a")
if err then if err then
minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err)) minetest.log("error", "[MOD] yl_speak_up Error saving NPC logfile: "..minetest.serialize(err))
return return
end
file:write(log_text)
file:close()
end end
file:write(log_text)
file:close()
-- log into a general all-npc-file as well -- log into a general all-npc-file as well
file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM.. local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM..
"log_ALL.txt", "a") "log_ALL.txt", "a")
if err then if err then
minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err)) minetest.log("error","[MOD] yl_speak_up Error saving NPC logfile: "..minetest.serialize(err))
return return
end end
file:write(tostring(n_id).." "..log_text) file:write(tostring(n_id).." "..log_text)
@ -47,7 +53,7 @@ end
-- this is used by yl_speak_up.eval_and_execute_function(..) in fs_edit_general.lua -- this is used by yl_speak_up.eval_and_execute_function(..) in fs_edit_general.lua
yl_speak_up.log_with_position = function(pname, n_id, text) yl_speak_up.log_with_position = function(pname, n_id, text, log_level)
if(not(pname) or not(yl_speak_up.speak_to[pname])) then if(not(pname) or not(yl_speak_up.speak_to[pname])) then
yl_speak_up.log_change(pname, n_id, yl_speak_up.log_change(pname, n_id,
"error: -npc not found- "..tostring(text)) "error: -npc not found- "..tostring(text))
@ -60,5 +66,5 @@ yl_speak_up.log_with_position = function(pname, n_id, text)
pos_str = minetest.pos_to_string(obj:get_pos(),0) pos_str = minetest.pos_to_string(obj:get_pos(),0)
end end
yl_speak_up.log_change(pname, n_id, yl_speak_up.log_change(pname, n_id,
"NPC at position "..pos_str.." "..tostring(text)) "NPC at position "..pos_str.." "..tostring(text), log_level)
end end

View File

@ -647,14 +647,10 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
local context_d_id = yl_speak_up.speak_to[pname].d_id local context_d_id = yl_speak_up.speak_to[pname].d_id
local active_dialog local active_dialog
if not player and not player:is_player() then if(not(dialog)) then
minetest.log( yl_speak_up.log_change(pname, n_id,
"action", "unconfigured NPC beeing talked to at "..
"[MOD] yl_speak_up: User " .. minetest.pos_to_string(player:get_pos()), "action")
pname ..
" talked to unconfigured NPC with ID n_" ..
n_id .. ", position of user was " .. minetest.pos_to_string(player:get_pos(), 0)
)
return yl_speak_up.get_error_message() return yl_speak_up.get_error_message()
end end
@ -684,13 +680,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
end end
else else
-- it may be possible that this player can initialize this npc -- it may be possible that this player can initialize this npc
minetest.log( yl_speak_up.log_change(pname, n_id,
"action", "unconfigured NPC beeing talked to at "..
"[MOD] yl_speak_up: User " .. minetest.pos_to_string(player:get_pos()), "action")
pname ..
" talked to unconfigured NPC with ID n_" ..
n_id .. ", position of user was " .. minetest.pos_to_string(player:get_pos(), 0)
)
-- this is the initial config -- this is the initial config
-- (input ends up at yl_speak_up.input_talk and needs to be rerouted) -- (input ends up at yl_speak_up.input_talk and needs to be rerouted)
return yl_speak_up.get_fs_initial_config(player, n_id, d_id, true) return yl_speak_up.get_fs_initial_config(player, n_id, d_id, true)