summaryrefslogtreecommitdiff
path: root/otfl-luat-ovr.lua
diff options
context:
space:
mode:
Diffstat (limited to 'otfl-luat-ovr.lua')
-rw-r--r--otfl-luat-ovr.lua84
1 files changed, 64 insertions, 20 deletions
diff --git a/otfl-luat-ovr.lua b/otfl-luat-ovr.lua
index 63a9e19..bd04eeb 100644
--- a/otfl-luat-ovr.lua
+++ b/otfl-luat-ovr.lua
@@ -7,30 +7,74 @@ if not modules then modules = { } end modules ['luat-ovr'] = {
}
-local write_nl, format, name = texio.write_nl, string.format, "luaotfload"
-local dummyfunction = function() end
+local module_name = "luaotfload"
-callbacks = {
- register = dummyfunction,
-}
+local texiowrite_nl = texio.write_nl
+local stringformat = string.format
+local tableconcat = table.concat
+local type = type
+
+--[[doc--
+We recreate the verbosity levels previously implemented in font-nms:
+
+ ==========================================================
+ lvl arg trace_loading trace_search suppress_output
+ ----------------------------------------------------------
+ (0) -> -q ⊥ ⊥ ⊤
+ (1) -> ∅ ⊥ ⊥ ⊥
+ (2) -> -v ⊤ ⊥ ⊥
+ (>2) -> -vv ⊤ ⊤ ⊥
+ ==========================================================
+
+--doc]]--
+local loglevel = 1 --- default
+local logout = "log"
-function logs.report(category,fmt,...)
- if fmt then
- write_nl('log', format("%s | %s: %s",name,category,format(fmt,...)))
- elseif category then
- write_nl('log', format("%s | %s",name,category))
- else
- write_nl('log', format("%s |",name))
+local set_loglevel = function (n)
+ if type(n) == "number" then
+ loglevel = n
end
end
+logs.set_loglevel = set_loglevel
+
+local set_logout = function (s)
+ if s == "stdout" then
+ logout = "term"
+ --else --- remains “log”
+ end
+end
+
+logs.set_logout = set_logout
+
+local log = function (category, fmt, ...)
+ local res = { module_name, " |" }
+ if category then res[#res+1] = " " .. category end
+ if fmt then res[#res+1] = ": " .. stringformat(fmt, ...) end
+ texiowrite_nl(logout, tableconcat(res))
+end
+
+local stdout = function (category, fmt, ...)
+ local res = { module_name, " |" }
+ if category then res[#res+1] = " " .. category end
+ if fmt then res[#res+1] = ": " .. stringformat(fmt, ...) end
+ texiowrite_nl(tableconcat(res))
+end
-function logs.info(category,fmt,...)
- if fmt then
- write_nl(format("%s | %s: %s",name,category,format(fmt,...)))
- elseif category then
- write_nl(format("%s | %s",name,category))
- else
- write_nl(format("%s |",name))
+local level_ids = { common = 0, loading = 1, search = 2 }
+
+logs.names_report = function (mode, lvl, ...)
+ if type(lvl) == "string" then
+ lvl = level_ids[lvl]
+ end
+ if not lvl then lvl = 0 end
+
+ if loglevel > lvl then
+ if mode == "log" then
+ log (...)
+ else
+ stdout (...)
+ end
end
- io.flush()
end
+
+-- vim:tw=71:sw=4:ts=4:expandtab