From 5876d11bc03c5a8fa32af1c00caf03c02fc4bc68 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 1 Oct 2019 22:18:50 +1000 Subject: Add the name of the test to any log messages about that test. And the original host as well. --- mirror-checker.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mirror-checker.lua b/mirror-checker.lua index 71c9c34..ae1b9b9 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -123,9 +123,14 @@ dumpTableSub = function (table, space) end return r end - - -local log = function(v, t, s) +local log = function(v, t, s, test, host) + local x = "" + if nil ~= test then x = x .. test end + if nil ~= host then + if #x > 0 then x = x .. " " end + x = x .. host + end + if #x > 0 then t = t .. "(" .. x .. ")" end if v <= verbosity then if 3 <= verbosity then t = os.date() .. " " .. t end print(t .. ": " .. s) @@ -137,8 +142,8 @@ local log = function(v, t, s) end local D = function(s) log(3, "DEBUG ", s) end local I = function(s) log(2, "INFO ", s) end -local W = function(s) log(1, "WARNING ", s) end -local E = function(s) log(0, "ERROR ", s) end +local W = function(s, t, h) log(1, "WARNING ", s, t, h) end +local E = function(s, t, h) log(0, "ERROR ", s, t, h) end local C = function(s) log(-1, "CRITICAL", s) end local mirrors = {} @@ -201,6 +206,8 @@ checkHEAD = function (host, URL, r, retry) if nil == r then r = 0 end if nil == retry then retry = 0 end local check = "Checking file" + local PU = url.parse(URL, defaultURL) + local pu = url.parse(PU.scheme .. "://" .. host, defaultURL) if 0 < r then check = "Redirecting to" end @@ -209,15 +216,13 @@ checkHEAD = function (host, URL, r, retry) check = "Retry " .. retry .. " " .. check end if 20 < r then - E("too many redirects! " .. check .. " " .. host .. " -> " .. URL) + E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) return end if 10 < retry then - E("too many retries! " .. check .. " " .. host .. " -> " .. URL) + E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) return end - local PU = url.parse(URL, defaultURL) - local pu = url.parse(PU.scheme .. "://" .. host, defaultURL) D(PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL) if not testing(PU.scheme, host) then D("Not testing " .. PU.scheme .. " " .. host .. " -> " .. URL); return end -- TODO - Perhaps we should try it anyway, and mark it as a warning if it DOES work? @@ -232,13 +237,13 @@ checkHEAD = function (host, URL, r, retry) local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"} if nil == s then s = "" end if nil == p then - E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL) + E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. -- Might be worthwhile retrying those, some number of times. if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end else if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then - E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) + E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) else I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) end @@ -246,12 +251,12 @@ checkHEAD = function (host, URL, r, retry) if nil ~= l then pu = url.parse(l, defaultURL) if (pu.scheme ~= PU.scheme) then - if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) end + if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l, PU.scheme, host) end if (pu.host == host) and pu.path == PU.path then D("Not testing protocol change " .. URL .. " -> " .. l); return end end if l == URL then - E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) + E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) elseif nil == pu.host then I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) -- cgit v1.1