From c2a115c27cac281a659c657014dde6c93c7566e1 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 25 Jun 2019 22:22:55 +1000 Subject: More fixes of the logging. Typo-- Use the base host name for the log file name, not the host/path. Actually check the open file return code. Close the log file at the end, though not really needed, coz Lua will close it at GC time. --- mirror-checker.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mirror-checker.lua b/mirror-checker.lua index c9dd870..cd95135 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -108,7 +108,7 @@ local log = function(v, t, s) print(t .. ": " .. s) end if nil ~= logFile then - logFile:write(os.date() .. " " .. t .. ": " .. s .. "/n") + logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") logFile:flush() end end @@ -381,12 +381,13 @@ end execute("mkdir -p results") if 0 < #arg then + local pu = url.parse("http://" .. arg[1], defaultURL) if nil ~= arg[2] then - logFile = io.open ("results/mirror-checker-lua_" .. arg[1] .. "_" .. arg[2] .. ".log", "a+") + logFile, e = io.open("results/mirror-checker-lua_" .. pu.host .. "_" .. arg[2] .. ".log", "a+") else - logFile = io.open ("results/mirror-checker-lua_" .. arg[1] .. ".log", "a+") + logFile, e = io.open("results/mirror-checker-lua_" .. pu.host .. ".log", "a+") end - local pu = url.parse("http://" .. arg[1], defaultURL) + if nil == logFile then C("opening log file - " .. e) end I("Starting tests for " ..pu.host .. " with these tests - " .. table.concat(options.tests.value, ", ")) if nil ~= arg[2] then I(" Using IP " .. arg[2]) end if testing("Integrity") or testing("Updated") then @@ -396,9 +397,11 @@ if 0 < #arg then checkExes(download) end checkHost(pu.host, pu.path, arg[2]) + logFile:close() else if not keep then os.execute("rm -f results/*.log") end - logFile = io.open ("results/mirror-checker-lua.log", "a+") + logFile, e = io.open("results/mirror-checker-lua.log", "a+") + if nil == logFile then C("opening log file - " .. e) end I("Starting tests " .. table.concat(options.tests.value, ", ")) execute("mkdir -p results") local mirrors = getMirrors() @@ -418,4 +421,5 @@ else if testing("Integrity") or testing("Updated") then while 1 < checkExes(download) do os.execute("sleep 30") end end + logFile:close() end -- cgit v1.1