OC-PsychOS/modules/debug/log.lua

30 lines
713 B
Lua
Raw Normal View History

2017-09-07 22:09:48 +10:00
_G.DEFAC, _G.DESEV = 6, 0
2017-07-30 19:12:10 +10:00
if component then
_G.Log = ""
2017-09-08 14:50:34 +10:00
_G.logt = {}
2017-07-30 19:12:10 +10:00
function log(...)
2017-09-07 22:09:48 +10:00
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)
2017-07-30 19:12:10 +10:00
end
2017-09-08 14:50:34 +10:00
logt[#logt+1] = "["..tostring(computer.uptime()).."] ["..tostring(sev).."] ["..tostring(fac).."] "..tostring(v)
2017-09-07 22:09:48 +10:00
computer.pushSignal("syslog",sev,fac,v)
2017-09-08 14:50:34 +10:00
if #logt > 16 then
table.remove(logt,1)
end
end
_G.Log = ""
2017-09-08 14:50:34 +10:00
for k,v in ipairs(logt) do
_G.Log=_G.Log .. v .. "\n"
2017-09-07 22:09:48 +10:00
end
2017-07-30 19:12:10 +10:00
end
print=log
else log = print
end