From dcd2b6166b9d4af38e6387d1f2ca482ea8ef7e1f Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 4 Apr 2014 16:37:16 +0100 Subject: [PATCH] elua: more logging functionality (utility funcs for default domain printing) --- src/bindings/luajit/eina/log.lua | 29 +++++++++++++++++++++++++++-- src/examples/elua/elm_test.lua | 10 ++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/bindings/luajit/eina/log.lua b/src/bindings/luajit/eina/log.lua index d1318bb083..c40be10487 100644 --- a/src/bindings/luajit/eina/log.lua +++ b/src/bindings/luajit/eina/log.lua @@ -103,13 +103,36 @@ M.log_full = log_full local getinfo = debug.getinfo +local getfuncname = function(info) + return info.name or "<" .. tostring(info.func) .. ">", info.currentline +end + local log = function(dom, level, msg, loff) local info = getinfo(2 + (loff or 0), "nlSf") - log_full(dom, level, info.source, - info.name or "<" .. tostring(info.func) .. ">", info.currentline, msg) + log_full(dom, level, info.source, getfuncname(info), info.currentline, msg) end M.log = log +local logfuncs = { + { "crit", C.EINA_LOG_LEVEL_CRITICAL }, + { "err", C.EINA_LOG_LEVEL_ERR }, + { "warn", C.EINA_LOG_LEVEL_WARN }, + { "info", C.EINA_LOG_LEVEL_INFO }, + { "dbg", C.EINA_LOG_LEVEL_DBG } +} + +for i, v in ipairs(logfuncs) do + M["log_" .. v[1]] = function(msg) + if not default_domain then return end + local info = getinfo(2, "nlSf") + local dom = ffi.cast("Domain_Private*", default_domain).domain + eina.eina_log_print(dom, v[2], info.source, getfuncname(info), + info.currentline, msg) + end +end + +logfuncs = nil + M.Domain_Base = util.Object:clone { set_level = function(self, level) local dom = get_dom(self) @@ -166,4 +189,6 @@ M.Domain = M.Domain_Base:clone { end } +M.set_default_domain = f + return M \ No newline at end of file diff --git a/src/examples/elua/elm_test.lua b/src/examples/elua/elm_test.lua index 95f362b2be..df7726fc97 100644 --- a/src/examples/elua/elm_test.lua +++ b/src/examples/elua/elm_test.lua @@ -7,6 +7,16 @@ local win = elm.Window("test", "Hello World") dom:log(log.level.INFO, "created window") dom:log(log.level.ERR, "error test!") +log.log_err("test with default log domain") + +local foo = function() + for i = 1, 4 do + dom:log(log.level.ERR, "testing: " .. i) + end +end + +foo() + win:smart_callback_add("delete,request", function() elm.exit() end)