diff --git a/fs_log.lua b/fs_log.lua index ee1ab48..7266118 100644 --- a/fs_log.lua +++ b/fs_log.lua @@ -2,7 +2,7 @@ -- 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 if(not(pname)) then pname = "- unkown player -" @@ -13,32 +13,38 @@ yl_speak_up.log_change = function(pname, n_id, text) if(not(text)) then text = "- no text given -" end + if(not(log_level)) then + log_level = "info" + end -- we don't want newlines in the texts text = string.gsub(text, "\n", "\\n") -- log in debug.txt 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 -- date needs to be inserted manually (minetest.log does it automaticly); -- 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") - -- actually append to the logfile - local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM.. + n_id = tostring(n_id) + 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") - if err then - minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err)) - return + if err then + minetest.log("error", "[MOD] yl_speak_up Error saving NPC logfile: "..minetest.serialize(err)) + return + end + file:write(log_text) + file:close() end - file:write(log_text) - file:close() -- 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") 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 end 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 -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 yl_speak_up.log_change(pname, n_id, "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) end 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 diff --git a/fs_talkdialog.lua b/fs_talkdialog.lua index df71cc0..41cbafc 100644 --- a/fs_talkdialog.lua +++ b/fs_talkdialog.lua @@ -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 active_dialog - if not player and not player:is_player() then - minetest.log( - "action", - "[MOD] yl_speak_up: User " .. - pname .. - " talked to unconfigured NPC with ID n_" .. - n_id .. ", position of user was " .. minetest.pos_to_string(player:get_pos(), 0) - ) + if(not(dialog)) then + yl_speak_up.log_change(pname, n_id, + "unconfigured NPC beeing talked to at ".. + minetest.pos_to_string(player:get_pos()), "action") return yl_speak_up.get_error_message() end @@ -684,13 +680,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec end else -- it may be possible that this player can initialize this npc - minetest.log( - "action", - "[MOD] yl_speak_up: User " .. - pname .. - " talked to unconfigured NPC with ID n_" .. - n_id .. ", position of user was " .. minetest.pos_to_string(player:get_pos(), 0) - ) + yl_speak_up.log_change(pname, n_id, + "unconfigured NPC beeing talked to at ".. + minetest.pos_to_string(player:get_pos()), "action") -- this is the initial config -- (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)