cctweaked_drone/lib/journal.lua
2026-07-17 13:54:31 +02:00

42 lines
1 KiB
Lua

--------------------------------------------------------------------
-- lib/journal.lua : journal de vol (console + fichier rotatif)
--------------------------------------------------------------------
local Journal = {}
local FICHIER, MAX_TAILLE = "drone.log", 64 * 1024
local function horodater(texte)
return ("[%s] %s"):format(textutils.formatTime(os.time("local"), true), texte)
end
local function ecrireFichier(ligne)
if fs.exists(FICHIER) and fs.getSize(FICHIER) > MAX_TAILLE then
fs.delete(FICHIER .. ".old")
fs.move(FICHIER, FICHIER .. ".old")
end
local f = fs.open(FICHIER, "a")
if f then
f.writeLine(ligne)
f.close()
end
end
function Journal.info(texte)
local ligne = horodater(texte)
print(ligne)
ecrireFichier(ligne)
end
function Journal.erreur(texte)
local ligne = horodater("ERREUR " .. texte)
printError(ligne)
ecrireFichier(ligne)
end
function Journal.alerte(texte)
local ligne = horodater("ALERTE " .. texte)
printError(ligne)
ecrireFichier(ligne)
end
return Journal