From 8d794525b3232dbe326043ee3d219ecabee04636 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Wed, 4 Dec 2019 10:08:03 +0100 Subject: Fix repeated log file opening/closing (H#136) --- advtrains/log.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advtrains/log.lua b/advtrains/log.lua index d2b71d3..d7053a2 100644 --- a/advtrains/log.lua +++ b/advtrains/log.lua @@ -5,9 +5,13 @@ advtrains.log = function() end if minetest.settings:get_bool("advtrains_enable_logging") then advtrains.logfile = advtrains.fpath .. "_log" + local log = io.open(advtrains.logfile, "a+") + function advtrains.log (event, player, pos, data) - local log = io.open(advtrains.logfile, "a+") log:write(os.date()..": "..event.." by "..player.." at "..minetest.pos_to_string(pos).." -- "..(data or "").."\n") - log:close() end + + minetest.register_on_shutdown(function() + log:close() + end) end -- cgit v1.2.3