multiple improvements to logging

- added style.log table
- removed contextmenu
- use ctrl+click to copy individual log entries
- use icon instead of + or - for log items in logview
This commit is contained in:
takase1121
2021-12-18 10:51:44 +08:00
parent 69de42b078
commit ab4ecd515b
7 changed files with 56 additions and 37 deletions
+14 -8
View File
@@ -1034,15 +1034,21 @@ function core.get_views_referencing_doc(doc)
end
local function log(icon, icon_color, fmt, ...)
local function log(level, show, fmt, ...)
local text = string.format(fmt, ...)
if icon then
core.status_view:show_message(icon, icon_color, text)
if show then
local s = style.log[level]
core.status_view:show_message(s.icon, s.color, text)
end
local info = debug.getinfo(2, "Sl")
local at = string.format("%s:%d", info.short_src, info.currentline)
local item = { text = text, time = os.time(), at = at }
local item = {
level = level,
text = text,
time = os.time(),
at = at
}
table.insert(core.log_items, item)
if #core.log_items > config.max_log_items then
table.remove(core.log_items, 1)
@@ -1052,17 +1058,17 @@ end
function core.log(...)
return log("i", style.text, ...)
return log("INFO", true, ...)
end
function core.log_quiet(...)
return log(nil, nil, ...)
return log("INFO", false, ...)
end
function core.error(...)
return log("!", style.accent, ...)
return log("ERROR", true, ...)
end
@@ -1075,7 +1081,7 @@ function core.get_log(i)
return table.concat(r, "\n")
end
local item = type(i) == "number" and core.log_items[i] or i
local text = string.format("[%s] %s at %s", os.date(nil, item.time), item.text, item.at)
local text = string.format("%s [%s] %s at %s", os.date(nil, item.time), item.level, item.text, item.at)
if item.info then
text = string.format("%s\n%s\n", text, item.info)
end