2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/dbg.lua
chrox a60544b1ad Koreader Ubuntu-touch port
Currently only tested on Ubuntu-touch emulator with framework
ubuntu-sdk-14.10 for armhf.
The ubuntu-touch port is binary compatible with the Kobo port
major changes in this PR are:
1. rename the emulator device to sdl device since both the emulator
and the ubuntu-touch target use libsdl to handle input/output.
2. ubuntu-touch app has no write access to the installation dir so
all write-outs should be in a seperate dir definded in `datastorage`.
2015-10-03 14:48:51 +08:00

55 lines
1.1 KiB
Lua

local dump = require("dump")
local isAndroid, android = pcall(require, "android")
local Dbg = {
is_on = false,
ev_log = nil,
}
local Dbg_mt = {}
local function LvDEBUG(lv, ...)
local line = ""
for i,v in ipairs({...}) do
if type(v) == "table" then
line = line .. " " .. dump(v, lv)
else
line = line .. " " .. tostring(v)
end
end
if isAndroid then
android.LOGI("#"..line)
else
print("#"..line)
io.stdout:flush()
end
end
function Dbg_mt.__call(dbg, ...)
if dbg.is_on then LvDEBUG(math.huge, ...) end
end
function Dbg:turnOn()
self.is_on = true
-- create or clear ev log file
self.ev_log = io.open("ev.log", "w")
end
function Dbg:logEv(ev)
local log = ev.type.."|"..ev.code.."|"
..ev.value.."|"..ev.time.sec.."|"..ev.time.usec.."\n"
if self.ev_log then
self.ev_log:write(log)
self.ev_log:flush()
end
end
function Dbg:traceback()
LvDEBUG(math.huge, debug.traceback())
end
setmetatable(Dbg, Dbg_mt)
return Dbg