From d2b0ff2d75f228d37f0f3d5491bfe11b134e2424 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 13 Nov 2019 20:36:38 +1000 Subject: HTMLize the logs. --- apt-panopticon.lua | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'apt-panopticon.lua') diff --git a/apt-panopticon.lua b/apt-panopticon.lua index b03810c..a8796c9 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -147,6 +147,18 @@ end local ip = "" local results = {} +local logPre = function() + if nil ~= logFile then + logFile:write("\n") + logFile:write("\n") + end +end +local logPost = function() + if nil ~= logFile then + logFile:write(" \n") + end +end + local log = function(v, t, s, prot, test, host) local x = "" if nil == prot then prot = "" end @@ -180,7 +192,13 @@ local log = function(v, t, s, prot, test, host) print(t .. ": " .. s) end if nil ~= logFile then - logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") + local colour = "white" + if -1 == v then colour = "fuchsia" end -- CRITICAL + if 0 == v then colour = "red " end -- ERROR + if 1 == v then colour = "yellow " end -- WARNING + if 2 == v then colour = "white " end -- INFO + if 3 == v then colour = "gray " end -- DEBUG + logFile:write(os.date() .. " " .. t .. ": " .. s .. "
\n") logFile:flush() end end @@ -639,11 +657,12 @@ if 0 < #arg then end local pu = url.parse("http://" .. arg[1]) if nil ~= arg[2] then - logFile, e = io.open("results/" .. pu.host .. "_" .. arg[2] .. ".log", "a+") + logFile, e = io.open("results/LOG_" .. pu.host .. "_" .. arg[2] .. ".html", "a+") else - logFile, e = io.open("results/" .. pu.host .. ".log", "a+") + logFile, e = io.open("results/LOG_" .. pu.host .. ".html", "a+") end if nil == logFile then C("opening log file - " .. e); return end + logPre() I("Starting tests for " ..arg[1] .. " with these tests - " .. table.concat(options.tests.value, ", ")) mirrors = loadfile("results/mirrors.lua")() if nil ~= arg[2] then I(" Using IP " .. arg[2]); ip = arg[2] end @@ -677,6 +696,7 @@ if 0 < #arg then else checkHost(pu.host, pu.host, pu.path, arg[2], arg[3]) end + logPost() logFile:close() local f = pu.host if "" ~= ip then f = f .. "_" .. ip end @@ -693,8 +713,9 @@ else end os.execute("rm -f results/*.check") os.execute("mkdir -p results; touch results/stamp") - logFile, e = io.open("results/apt-panopticon.log", "a+") + logFile, e = io.open("results/LOG_apt-panopticon.html", "a+") if nil == logFile then C("opening log file - " .. e); return end + logPre() I("Starting tests " .. table.concat(options.tests.value, ", ")) execute("mkdir -p results") mirrors = getMirrors() @@ -731,6 +752,6 @@ else execute("./" .. report .. " ") end end - + logPost() logFile:close() end -- cgit v1.1