OC-PsychOS/modules/debug/log.lua

30 lines
713 B
Lua

_G.DEFAC, _G.DESEV = 6, 0
if component then
_G.Log = ""
_G.logt = {}
function log(...)
local ta = {...}
local sev, fac = _G.DEFAC, _G.DESEV
if ta[#ta] == true then
ta[#ta] = nil
sev, fac = table.remove(ta,#ta),table.remove(ta,#ta)
end
for k,v in ipairs(ta) do
if component.list("ocemu")() then
component.invoke(component.list("ocemu")(),"log",v)
end
logt[#logt+1] = "["..tostring(computer.uptime()).."] ["..tostring(sev).."] ["..tostring(fac).."] "..tostring(v)
computer.pushSignal("syslog",sev,fac,v)
if #logt > 16 then
table.remove(logt,1)
end
end
_G.Log = ""
for k,v in ipairs(logt) do
_G.Log=_G.Log .. v .. "\n"
end
end
print=log
else log = print
end