moved logging into fs_log.lua and logged in extra npc log files
This commit is contained in:
parent
4067fd8f59
commit
32a0613780
@ -112,6 +112,9 @@ yl_speak_up.inventory_path = "yl_speak_up_inventories"
|
||||
-- Where shall player-specific varialbes (usually quest states) be stored?
|
||||
yl_speak_up.player_vars_save_file = "yl_speak_up_player_vars"
|
||||
|
||||
-- Where to store the logfiles for the individual NPC
|
||||
yl_speak_up.log_path = "yl_speak_up_log"
|
||||
|
||||
-- amount of time in seconds that has to have passed before the above file will be saved again
|
||||
-- (more time can pass if no variable is changed)
|
||||
yl_speak_up.player_vars_min_save_time = 60
|
||||
@ -246,4 +249,3 @@ local function read_skins_and_capes_from_folders(races)
|
||||
end
|
||||
end
|
||||
read_skins_and_capes_from_folders({"dwarf","elf","goblin","human","npc","orc"})
|
||||
|
||||
|
36
fs_log.lua
Normal file
36
fs_log.lua
Normal file
@ -0,0 +1,36 @@
|
||||
-- handle logging
|
||||
|
||||
|
||||
-- log changes done by players or admins to NPCs
|
||||
yl_speak_up.log_change = function(pname, n_id, text)
|
||||
-- make sure all variables are defined
|
||||
if(not(pname)) then
|
||||
pname = "- unkown player -"
|
||||
end
|
||||
if(not(n_id)) then
|
||||
n_id = "- unknown NPC -"
|
||||
end
|
||||
if(not(text)) then
|
||||
text = "- no text given -"
|
||||
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)
|
||||
|
||||
-- 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..
|
||||
"log_"..n_id..".txt", "a")
|
||||
if err then
|
||||
minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err))
|
||||
return
|
||||
end
|
||||
file:write(log_text)
|
||||
file:close()
|
||||
end
|
@ -528,27 +528,3 @@ yl_speak_up.may_edit_npc = function(player, n_id)
|
||||
or (yl_speak_up.speak_to[pname]
|
||||
and yl_speak_up.speak_to[pname].may_edit_this_npc))
|
||||
end
|
||||
|
||||
|
||||
-- log changes done by players or admins to NPCs
|
||||
yl_speak_up.log_change = function(pname, n_id, text)
|
||||
-- make sure all variables are defined
|
||||
if(not(pname)) then
|
||||
pname = "- unkown player -"
|
||||
end
|
||||
if(not(n_id)) then
|
||||
n_id = "- unknown NPC -"
|
||||
end
|
||||
if(not(text)) then
|
||||
text = "- no text given -"
|
||||
end
|
||||
-- we don't want newlines in the texts
|
||||
text = string.gsub(text, "\n", "\\n")
|
||||
|
||||
local log_text = "<"..tostring(n_id).."> ["..tostring(pname).."]: "..text
|
||||
-- log in general logfile
|
||||
minetest.log("yl_speak_up "..log_text)
|
||||
-- log with timestamp
|
||||
local log_text = tostring(os.time())..log_text
|
||||
-- TODO: log in a file for each npc and show it on demand?
|
||||
end
|
||||
|
3
init.lua
3
init.lua
@ -28,6 +28,8 @@ yl_speak_up.custom_server_functions = {}
|
||||
|
||||
-- the server-specific configuration
|
||||
dofile(modpath .. "config.lua")
|
||||
-- logging and showing the log
|
||||
dofile(modpath .. "fs_log.lua")
|
||||
-- players *and* npc need privs for certain things
|
||||
dofile(modpath .. "privs.lua")
|
||||
-- contains the command to hand out privs to NPC
|
||||
@ -127,6 +129,7 @@ end
|
||||
|
||||
minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.path)
|
||||
minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.inventory_path)
|
||||
minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.log_path)
|
||||
|
||||
yl_speak_up.mob_table = yl_speak_up.init_mob_table() or {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user