From ea8cd771135d573fee6529e62e08468e79b12eab Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 18 Sep 2014 11:17:00 +0200 Subject: beta 2014.09.18 11:17 --- tex/context/base/trac-log.lua | 365 +++++++++++++++++++++++++++--------------- 1 file changed, 234 insertions(+), 131 deletions(-) (limited to 'tex/context/base/trac-log.lua') diff --git a/tex/context/base/trac-log.lua b/tex/context/base/trac-log.lua index 8e83bbafa..90da5cfe4 100644 --- a/tex/context/base/trac-log.lua +++ b/tex/context/base/trac-log.lua @@ -9,69 +9,11 @@ if not modules then modules = { } end modules ['trac-log'] = { -- In fact all writes could go through lua and we could write the console and -- terminal handler in lua then. Ok, maybe it's slower then, so a no-go. --- if tex and (tex.jobname or tex.formatname) then --- --- -- quick hack, awaiting speedup in engine (8 -> 6.4 sec for --make with console2) --- -- still needed for luajittex --- --- local texio_write_nl = texio.write_nl --- local texio_write = texio.write --- local io_write = io.write --- --- local write_nl = function(target,...) --- if not io_write then --- io_write = io.write --- end --- if target == "term and log" then --- texio_write_nl("log",...) --- texio_write_nl("term","") --- io_write(...) --- elseif target == "log" then --- texio_write_nl("log",...) --- elseif target == "term" then --- texio_write_nl("term","") --- io_write(...) --- else --- texio_write_nl("log",target,...) --- texio_write_nl("term","") --- io_write(target,...) --- end --- end --- --- local write = function(target,...) --- if not io_write then --- io_write = io.write --- end --- if target == "term and log" then --- texio_write("log",...) --- io_write(...) --- elseif target == "log" then --- texio_write("log",...) --- elseif target == "term" then --- io_write(...) --- else --- texio_write("log",target,...) --- io_write(target,...) --- end --- end --- --- texio.write = write --- texio.write_nl = write_nl --- --- else --- --- -- texlua or just lua --- --- end - --- todo: less categories, more subcategories (e.g. nodes) --- todo: split into basics and ctx specific - +local next, type, select, print = next, type, select, print local write_nl, write = texio and texio.write_nl or print, texio and texio.write or io.write local format, gmatch, find = string.format, string.gmatch, string.find local concat, insert, remove = table.concat, table.insert, table.remove local topattern = string.topattern -local next, type, select = next, type, select local utfchar = utf.char local datetime = os.date local openfile = io.open @@ -81,6 +23,14 @@ local formatters = string.formatters local texgetcount = tex and tex.getcount +-- variant is set now + +local variant = "default" +-- local variant = "ansi" + +-- todo: less categories, more subcategories (e.g. nodes) +-- todo: split into basics and ctx specific + --[[ldx--

This is a prelude to a more extensive logging module. We no longer provide based logging as parsing is relatively easy anyway.

@@ -114,12 +64,12 @@ wiki : http://contextgarden.net -- [[local chruni = utilities.strings.chruni]] -- ) -utilities.strings.formatters.add ( +formatters.add ( formatters, "unichr", [["U+" .. format("%%05X",%s) .. " (" .. utfchar(%s) .. ")"]] ) -utilities.strings.formatters.add ( +formatters.add ( formatters, "chruni", [[utfchar(%s) .. " (U+" .. format("%%05X",%s) .. ")"]] ) @@ -154,18 +104,125 @@ local report, subreport, status, settarget, setformats, settranslations local direct, subdirect, writer, pushtarget, poptarget, setlogfile, settimedlog, setprocessor, setformatters +-- we use formatters but best check for % then because for simple messages but +-- we don't want this overhead for single messages (not that there are that +-- many; we could have a special weak table) + if tex and (tex.jobname or tex.formatname) then - -- local format = string.formatter + local function useluawrites() + + -- quick hack, awaiting speedup in engine (8 -> 6.4 sec for --make with console2) + -- still needed for luajittex .. luatex should not have that ^^ mess + + local texio_write_nl = texio.write_nl + local texio_write = texio.write + local io_write = io.write + + write_nl = function(target,...) + if not io_write then + io_write = io.write + end + if target == "term and log" then + texio_write_nl("log",...) + texio_write_nl("term","") + io_write(...) + elseif target == "log" then + texio_write_nl("log",...) + elseif target == "term" then + texio_write_nl("term","") + io_write(...) + elseif target ~= "none" then + texio_write_nl("log",target,...) + texio_write_nl("term","") + io_write(target,...) + end + end + + write = function(target,...) + if not io_write then + io_write = io.write + end + if target == "term and log" then + texio_write("log",...) + io_write(...) + elseif target == "log" then + texio_write("log",...) + elseif target == "term" then + io_write(...) + elseif target ~= "none" then + texio_write("log",target,...) + io_write(target,...) + end + end - local valueiskey = { __index = function(t,k) t[k] = k return k end } -- will be helper + texio.write = write + texio.write_nl = write_nl - local target = "term and log" + useluawrites = ignore - logs.flush = io.flush + end + + -- local format = string.formatter + + local whereto = "both" + local target = nil + local targets = nil + + local formats = table.setmetatableindex("self") + local translations = table.setmetatableindex("self") + + local report_yes, subreport_yes, direct_yes, subdirect_yes, status_yes + local report_nop, subreport_nop, direct_nop, subdirect_nop, status_nop + + local variants = { + default = { + formats = { + report_yes = formatters["%-15s > %s\n"], + report_nop = formatters["%-15s >\n"], + direct_yes = formatters["%-15s > %s"], + direct_nop = formatters["%-15s >"], + subreport_yes = formatters["%-15s > %s > %s\n"], + subreport_nop = formatters["%-15s > %s >\n"], + subdirect_yes = formatters["%-15s > %s > %s"], + subdirect_nop = formatters["%-15s > %s >"], + status_yes = formatters["%-15s : %s\n"], + status_nop = formatters["%-15s :\n"], + }, + targets = { + logfile = "log", + log = "log", + file = "log", + console = "term", + terminal = "term", + both = "term and log", + }, + }, + ansi = { + formats = { + report_yes = formatters["%-15s > %s\n"], + report_nop = formatters["%-15s >\n"], + direct_yes = formatters["%-15s > %s"], + direct_nop = formatters["%-15s >"], + subreport_yes = formatters["%-15s > %s > %s\n"], + subreport_nop = formatters["%-15s > %s >\n"], + subdirect_yes = formatters["%-15s > %s > %s"], + subdirect_nop = formatters["%-15s > %s >"], + status_yes = formatters["%-15s : %s\n"], + status_nop = formatters["%-15s :\n"], + }, + targets = { + logfile = "none", + log = "none", + file = "none", + console = "term", + terminal = "term", + both = "term", + }, + } + } - local formats = { } setmetatable(formats, valueiskey) - local translations = { } setmetatable(translations,valueiskey) + logs.flush = io.flush writer = function(...) write_nl(target,...) @@ -175,13 +232,6 @@ if tex and (tex.jobname or tex.formatname) then write_nl(target,"\n") end - local report_yes = formatters["%-15s > %s\n"] - local report_nop = formatters["%-15s >\n"] - - -- we can use formatters but best check for % then because for simple messages - -- we con't want this overhead for single messages (not that there are that - -- many; we could have a special weak table) - report = function(a,b,c,...) if c then write_nl(target,report_yes(translations[a],formatters[formats[b]](c,...))) @@ -194,9 +244,6 @@ if tex and (tex.jobname or tex.formatname) then end end - local direct_yes = formatters["%-15s > %s"] - local direct_nop = formatters["%-15s >"] - direct = function(a,b,c,...) if c then return direct_yes(translations[a],formatters[formats[b]](c,...)) @@ -209,9 +256,6 @@ if tex and (tex.jobname or tex.formatname) then end end - local subreport_yes = formatters["%-15s > %s > %s\n"] - local subreport_nop = formatters["%-15s > %s >\n"] - subreport = function(a,s,b,c,...) if c then write_nl(target,subreport_yes(translations[a],translations[s],formatters[formats[b]](c,...))) @@ -224,9 +268,6 @@ if tex and (tex.jobname or tex.formatname) then end end - local subdirect_yes = formatters["%-15s > %s > %s"] - local subdirect_nop = formatters["%-15s > %s >"] - subdirect = function(a,s,b,c,...) if c then return subdirect_yes(translations[a],translations[s],formatters[formats[b]](c,...)) @@ -239,9 +280,6 @@ if tex and (tex.jobname or tex.formatname) then end end - local status_yes = formatters["%-15s : %s\n"] - local status_nop = formatters["%-15s :\n"] - status = function(a,b,c,...) if c then write_nl(target,status_yes(translations[a],formatters[formats[b]](c,...))) @@ -254,17 +292,13 @@ if tex and (tex.jobname or tex.formatname) then end end - local targets = { - logfile = "log", - log = "log", - file = "log", - console = "term", - terminal = "term", - both = "term and log", - } - - settarget = function(whereto) - target = targets[whereto or "both"] or targets.both + settarget = function(askedwhereto) + whereto = askedwhereto or whereto or "both" + target = targets[whereto] + if not target then + whereto = "both" + target = targets[whereto] + end if target == "term" or target == "term and log" then logs.flush = io.flush else @@ -300,24 +334,81 @@ if tex and (tex.jobname or tex.formatname) then end end - setformatters = function(f) - report_yes = f.report_yes or report_yes - report_nop = f.report_nop or report_nop - subreport_yes = f.subreport_yes or subreport_yes - subreport_nop = f.subreport_nop or subreport_nop - direct_yes = f.direct_yes or direct_yes - direct_nop = f.direct_nop or direct_nop - subdirect_yes = f.subdirect_yes or subdirect_yes - subdirect_nop = f.subdirect_nop or subdirect_nop - status_yes = f.status_yes or status_yes - status_nop = f.status_nop or status_nop + setformatters = function(specification) + local t = nil + local f = nil + local d = variants.default + if not specification then + -- + elseif type(specification) == "table" then + t = specification.targets + f = specification.formats or specification + else + local v = variants[specification] + if v then + t = v.targets + f = v.formats + variant = specification + end + end + targets = t or d.targets + target = targets[whereto] or target + if f then + d = d.formats + else + f = d.formats + d = f + end + setmetatableindex(f,d) + report_yes = f.report_yes + report_nop = f.report_nop + subreport_yes = f.subreport_yes + subreport_nop = f.subreport_nop + direct_yes = f.direct_yes + direct_nop = f.direct_nop + subdirect_yes = f.subdirect_yes + subdirect_nop = f.subdirect_nop + status_yes = f.status_yes + status_nop = f.status_nop + if variant == "ansi" then + useluawrites() -- because tex escapes ^^ + end + settarget(whereto) end + setformatters(variant) + setlogfile = ignore settimedlog = ignore else + local report_yes, subreport_yes, status_yes + local report_nop, subreport_nop, status_nop + + local variants = { + default = { + formats = { + report_yes = formatters["%-15s | %s"], + report_nop = formatters["%-15s |"], + subreport_yes = formatters["%-15s | %s | %s"], + subreport_nop = formatters["%-15s | %s |"], + status_yes = formatters["%-15s : %s\n"], + status_nop = formatters["%-15s :\n"], + }, + }, + ansi = { + formats = { + report_yes = formatters["%-15s | %s"], + report_nop = formatters["%-15s |"], + subreport_yes = formatters["%-15s | %s | %s"], + subreport_nop = formatters["%-15s | %s |"], + status_yes = formatters["%-15s : %s\n"], + status_nop = formatters["%-15s :\n"], + }, + }, + } + logs.flush = ignore writer = function(s) @@ -328,9 +419,6 @@ else write_nl("\n") end - local report_yes = formatters["%-15s | %s"] - local report_nop = formatters["%-15s |"] - report = function(a,b,c,...) if c then write_nl(report_yes(a,formatters[b](c,...))) @@ -343,9 +431,6 @@ else end end - local subreport_yes = formatters["%-15s | %s | %s"] - local subreport_nop = formatters["%-15s | %s |"] - subreport = function(a,sub,b,c,...) if c then write_nl(subreport_yes(a,sub,formatters[b](c,...))) @@ -358,9 +443,6 @@ else end end - local status_yes = formatters["%-15s : %s\n"] - local status_nop = formatters["%-15s :\n"] - status = function(a,b,c,...) -- not to be used in lua anyway if c then write_nl(status_yes(a,formatters[b](c,...))) @@ -389,15 +471,36 @@ else end end - setformatters = function(f) - report_yes = f.report_yes or report_yes - report_nop = f.report_nop or report_nop - subreport_yes = f.subreport_yes or subreport_yes - subreport_nop = f.subreport_nop or subreport_nop - status_yes = f.status_yes or status_yes - status_nop = f.status_nop or status_nop + setformatters = function(specification) + local f = nil + local d = variants.default + if specification then + if type(specification) == "table" then + f = specification.formats or specification + else + local v = variants[specification] + if v then + f = v.formats + end + end + end + if f then + d = d.formats + else + f = d.formats + d = f + end + setmetatableindex(f,d) + report_yes = f.report_yes + report_nop = f.report_nop + subreport_yes = f.subreport_yes + subreport_nop = f.subreport_nop + status_yes = f.status_yes + status_nop = f.status_nop end + setformatters(variant) + setlogfile = function(name,keepopen) if name and name ~= "" then local localtime = os.localtime @@ -728,13 +831,13 @@ logs.simpleline = simple -- obsolete -function logs.setprogram () end -- obsolete -function logs.extendbanner() end -- obsolete -function logs.reportlines () end -- obsolete -function logs.reportbanner() end -- obsolete -function logs.reportline () end -- obsolete -function logs.simplelines () end -- obsolete -function logs.help () end -- obsolete +logs.setprogram = ignore -- obsolete +logs.extendbanner = ignore -- obsolete +logs.reportlines = ignore -- obsolete +logs.reportbanner = ignore -- obsolete +logs.reportline = ignore -- obsolete +logs.simplelines = ignore -- obsolete +logs.help = ignore -- obsolete -- applications -- cgit v1.2.3