mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Remove deprecated modlib.log module
This commit is contained in:
parent
9e4ee70e21
commit
644c00aae1
6
init.lua
6
init.lua
@ -71,7 +71,7 @@ end
|
||||
|
||||
-- aliases
|
||||
-- more aliases are implemented below:
|
||||
-- modlib.[mod|log|conf|player] are aliases of modlib.minetest.[mod|log|conf|player] respectively
|
||||
-- modlib.[mod|conf] are aliases of modlib.minetest.[mod|conf] respectively
|
||||
modules.string = "text"
|
||||
modules.number = "math"
|
||||
|
||||
@ -99,10 +99,6 @@ end
|
||||
local function load_module(self, module_name_or_alias)
|
||||
local module_name = modules[module_name_or_alias]
|
||||
if not module_name then
|
||||
-- Handle modlib.[log|player] aliases for the minetest.[log|player] modules
|
||||
if module_name_or_alias == "log" then
|
||||
return modlib.minetest.log
|
||||
end
|
||||
-- no such module
|
||||
return
|
||||
end
|
||||
|
@ -3,7 +3,6 @@ local _ENV = {}
|
||||
local components = {}
|
||||
for _, value in pairs{
|
||||
"mod",
|
||||
"log",
|
||||
"conf", -- deprecated
|
||||
"luon",
|
||||
"raycast",
|
||||
|
@ -1,87 +0,0 @@
|
||||
-- Localize globals
|
||||
local ipairs, minetest, modlib, os, pairs, table = ipairs, minetest, modlib, os, pairs, table
|
||||
|
||||
-- Set environment
|
||||
local _ENV = {}
|
||||
setfenv(1, _ENV)
|
||||
|
||||
-- Log helpers - write to log, force writing to file
|
||||
minetest.mkdir(minetest.get_worldpath() .. "/logs")
|
||||
channels = {}
|
||||
last_day = os.date("%d")
|
||||
function get_path(logname)
|
||||
return minetest.get_worldpath() .. "/logs/" .. logname
|
||||
end
|
||||
function create_channel(title)
|
||||
local dir = get_path(title)
|
||||
minetest.mkdir(dir)
|
||||
channels[title] = {dirname = dir, queue = {}}
|
||||
write(title, "Initialisation")
|
||||
end
|
||||
function write(channelname, msg)
|
||||
local channel = channels[channelname]
|
||||
local current_day = os.date("%d")
|
||||
if current_day ~= last_day then
|
||||
last_day = current_day
|
||||
write_to_file(channelname, channel, os.date("%Y-%m-%d"))
|
||||
end
|
||||
table.insert(channel.queue, os.date("[%H:%M:%S] ") .. msg)
|
||||
end
|
||||
function write_to_all(msg)
|
||||
for channelname, _ in pairs(channels) do
|
||||
write(channelname, msg)
|
||||
end
|
||||
end
|
||||
function write_to_file(name, channel, current_date)
|
||||
if not channel then
|
||||
channel = channels[name]
|
||||
end
|
||||
if #(channel.queue) > 0 then
|
||||
local filename = channel.dirname .. "/" .. (current_date or os.date("%Y-%m-%d")) .. ".txt"
|
||||
local rope = {}
|
||||
for _, msg in ipairs(channel.queue) do
|
||||
table.insert(rope, msg)
|
||||
end
|
||||
modlib.file.append(filename, table.concat(rope, "\n") .. "\n")
|
||||
channels[name].queue = {}
|
||||
end
|
||||
end
|
||||
function write_all_to_file()
|
||||
local current_date = os.date("%Y-%m-%d")
|
||||
for name, channel in pairs(channels) do
|
||||
write_to_file(name, channel, current_date)
|
||||
end
|
||||
end
|
||||
function write_safe(channelname, msg)
|
||||
write(channelname, msg)
|
||||
write_all_to_file()
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
|
||||
minetest.register_globalstep(
|
||||
function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer > 5 then
|
||||
write_all_to_file()
|
||||
timer = 0
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_mods_loaded(
|
||||
function()
|
||||
write_to_all("Mods loaded")
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_shutdown(
|
||||
function()
|
||||
write_to_all("Shutdown")
|
||||
write_all_to_file()
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
-- Export environment
|
||||
return _ENV
|
Loading…
Reference in New Issue
Block a user