2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/dbg.lua

52 lines
1.0 KiB
Lua
Raw Normal View History

2013-10-18 20:38:07 +00:00
local DocSettings = require("docsettings") -- for dump method
local isAndroid, android = pcall(require, "android")
2013-03-12 17:18:53 +00:00
2013-10-18 20:38:07 +00:00
local Dbg = {
2014-03-13 13:52:43 +00:00
is_on = false,
ev_log = nil,
2013-03-12 17:18:53 +00:00
}
2013-10-18 20:38:07 +00:00
local Dbg_mt = {}
local function LvDEBUG(lv, ...)
2014-03-13 13:52:43 +00:00
local line = ""
for i,v in ipairs({...}) do
if type(v) == "table" then
line = line .. " " .. DocSettings:dump(v, lv)
else
line = line .. " " .. tostring(v)
end
end
if isAndroid then
android.LOGI("#"..line)
else
print("#"..line)
end
2013-10-18 20:38:07 +00:00
end
function Dbg_mt.__call(dbg, ...)
2014-03-13 13:52:43 +00:00
if dbg.is_on then LvDEBUG(math.huge, ...) end
2013-10-18 20:38:07 +00:00
end
2013-03-12 17:18:53 +00:00
function Dbg:turnOn()
2014-03-13 13:52:43 +00:00
self.is_on = true
2013-03-12 17:18:53 +00:00
2014-03-13 13:52:43 +00:00
-- create or clear ev log file
self.ev_log = io.open("ev.log", "w")
2013-03-12 17:18:53 +00:00
end
function Dbg:logEv(ev)
2014-03-13 13:52:43 +00:00
local log = ev.type.."|"..ev.code.."|"
..ev.value.."|"..ev.time.sec.."|"..ev.time.usec.."\n"
self.ev_log:write(log)
self.ev_log:flush()
2013-03-12 17:18:53 +00:00
end
2013-10-25 12:07:58 +00:00
function Dbg:traceback()
2014-03-13 13:52:43 +00:00
LvDEBUG(math.huge, debug.traceback())
2013-10-25 12:07:58 +00:00
end
2013-10-18 20:38:07 +00:00
setmetatable(Dbg, Dbg_mt)
2013-10-18 20:38:07 +00:00
return Dbg