forked from your-land-mirror/yl_speak_up
		
	improved logging
This commit is contained in:
		
							parent
							
								
									6fe611a267
								
							
						
					
					
						commit
						940768de19
					
				@ -21,8 +21,8 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
 | 
			
		||||
 | 
			
		||||
        local code = x_v[ id_prefix.."value" ]
 | 
			
		||||
        if code:byte(1) == 27 then
 | 
			
		||||
		yl_speak_up.log_error_with_position(pname, n_id,
 | 
			
		||||
			"could not compile the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
		yl_speak_up.log_with_position(pname, n_id,
 | 
			
		||||
			"error: could not compile the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
			" because of illegal bytecode for player "..tostring(pname))
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
@ -33,8 +33,8 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
 | 
			
		||||
        local f, msg = loadstring("return function("..param..") " .. code .. " end")
 | 
			
		||||
 | 
			
		||||
        if not f then
 | 
			
		||||
		yl_speak_up.log_error_with_position(pname, n_id,
 | 
			
		||||
			"could not compile the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
		yl_speak_up.log_with_position(pname, n_id,
 | 
			
		||||
			"error: could not compile the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
			" for player "..tostring(pname))
 | 
			
		||||
        else
 | 
			
		||||
            local func = f()
 | 
			
		||||
@ -42,8 +42,8 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
 | 
			
		||||
            local ok, ret = pcall(func,pname)
 | 
			
		||||
 | 
			
		||||
            if not ok then
 | 
			
		||||
		yl_speak_up.log_error_with_position(pname, n_id,
 | 
			
		||||
			"could not execute the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
		yl_speak_up.log_with_position(pname, n_id,
 | 
			
		||||
			"error: could not execute the content of "..tostring(x_id).." :"..dump(code)..
 | 
			
		||||
			" for player "..tostring(pname))
 | 
			
		||||
            end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								fs_log.lua
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								fs_log.lua
									
									
									
									
									
								
							@ -33,10 +33,21 @@ yl_speak_up.log_change = function(pname, n_id, text)
 | 
			
		||||
	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..
 | 
			
		||||
					"log_ALL.txt", "a")
 | 
			
		||||
	if err then
 | 
			
		||||
		minetest.log("[yl_speak_up] Error saving NPC logfile: "..minetest.serialize(err))
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	file:write(tostring(n_id).." "..log_text)
 | 
			
		||||
	file:close()
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- this is used by yl_speak_up.eval_and_execute_function(..) in fs_edit_general.lua
 | 
			
		||||
yl_speak_up.log_error_with_position = function(pname, n_id, text)
 | 
			
		||||
yl_speak_up.log_with_position = function(pname, n_id, text)
 | 
			
		||||
	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))
 | 
			
		||||
@ -49,5 +60,5 @@ yl_speak_up.log_error_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,
 | 
			
		||||
		"error: NPC at position "..pos_str.." "..tostring(text))
 | 
			
		||||
		"NPC at position "..pos_str.." "..tostring(text))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								tools.lua
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								tools.lua
									
									
									
									
									
								
							@ -90,11 +90,10 @@ minetest.register_tool("yl_speak_up:staff_of_game_over", {
 | 
			
		||||
		local luaentity = obj:get_luaentity()
 | 
			
		||||
		local npc = luaentity.yl_speak_up.id
 | 
			
		||||
 | 
			
		||||
		minetest.chat_send_player(p_name,"NPC with ID "..npc.." removed from position "..
 | 
			
		||||
		minetest.chat_send_player(p_name,"NPC with ID n_"..npc.." removed from position "..
 | 
			
		||||
			minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
 | 
			
		||||
		minetest.log("action","[MOD] yl_speak_up: NPC with ID "..npc..
 | 
			
		||||
			" removed from position "..minetest.pos_to_string(obj:get_pos(),0)..
 | 
			
		||||
			" on command of "..p_name)
 | 
			
		||||
		yl_speak_up.log_change(p_name, "n_"..tostring(npc),
 | 
			
		||||
			"removed with Staff of game-over")
 | 
			
		||||
		obj:remove()
 | 
			
		||||
		return itemstack
 | 
			
		||||
	end
 | 
			
		||||
@ -117,8 +116,8 @@ minetest.register_tool("yl_speak_up:staff_of_fashion", {
 | 
			
		||||
		yl_speak_up.fashion(user, obj)
 | 
			
		||||
		minetest.chat_send_player(p_name,"NPC with ID n_"..npc.." will redress at pos "..
 | 
			
		||||
			minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
 | 
			
		||||
		minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc.." will redress at pos "..
 | 
			
		||||
			minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
 | 
			
		||||
		yl_speak_up.log_change(p_name, "n_"..tostring(npc),
 | 
			
		||||
			"changed skin with Staff of fashion")
 | 
			
		||||
		return itemstack
 | 
			
		||||
	end
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user