diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2017-01-28 20:41:15 +0100 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2017-01-29 01:11:19 +0100 |
commit | be76d78b894022622622050e3cc5fcd882b54acc (patch) | |
tree | 02df00680e83a56b44bd78f09f3aa8278391ae0e | |
parent | b0cb116048d189b72d15f1a6c19f0fb365e65d40 (diff) | |
download | luaotfload-be76d78b894022622622050e3cc5fcd882b54acc.tar.gz |
[log] handle logging more defensively
-rw-r--r-- | src/luaotfload-log.lua | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/luaotfload-log.lua b/src/luaotfload-log.lua index 5b2f1f3..6a41590 100644 --- a/src/luaotfload-log.lua +++ b/src/luaotfload-log.lua @@ -14,6 +14,7 @@ because we lack a user interface to toggle per-subsystem tracing. --doc]]-- local module_name = "luaotfload" --- prefix for messages +local debug = debug luaotfload = luaotfload or { } luaotfload.log = luaotfload.log or { } @@ -132,10 +133,33 @@ end log.set_logout = set_logout +local format_error_handler +if debug then + local debugtraceback = debug.traceback + format_error_handler = function (err) + print "" + print (stringformat ("luaotfload error: %q", err)) + print (stringformat ("Lua interpreter %s", debugtraceback ())) + print "" + end +else + format_error_handler = function (err) + print "" + print (stringformat ("luaotfload error: %q", err)) + print "Lua debug module not available; please enable for a backtrace" + print "" + end +end + local basic_logger = function (category, fmt, ...) - local res = { module_name, "|", category, ":" } + local res = { module_name, "|", category or "UNKNOWN", ":" } if fmt then - res [#res + 1] = stringformat (fmt, ...) + local ok, val = xpcall (stringformat, format_error_handler, fmt, ...) + if ok then + res [#res + 1] = val + else + res [#res + 1] = stringformat ("ERROR: %q", val) + end end texiowrite_nl (logout, tableconcat(res, " ")) end @@ -354,4 +378,4 @@ local texioreporter = function (message) end texio.reporter = texioreporter - +--- vim:shiftwidth=4:expandtab:ft=lua |