Commit 01fa13ec authored by Natanael Copa's avatar Natanael Copa

avoid duplicate code using function variables

the code for handling dg and squid log files are identical, except the
parse and import function. We pass the correct function as a param
and reuse the code.
parent c5002b34
......@@ -848,6 +848,18 @@ function testsource(sourcename)
return result
end
-- import either squid or dg log file.
-- delete logfile after
function importlogfile(source, cookiesfile, file, parselog_func, importlog_func)
logme("Processing " .. file )
logme("Getting " .. file )
logcontent = getlogfile(source, cookiesfile, file)
logentries = parselog_func(logcontent)
importlog(logentries, source.sourcename)
logme("Deleting " .. file )
deletelogfile(source, cookiesfile, file)
end
function importlogs()
local result = cfe({ label="Weblog Import Logs Result" })
local count = 0
......@@ -867,22 +879,10 @@ function importlogs()
for j,file in ipairs(files) do
if string.match(file, "dansguardian/access%.log[%.%-]") then
count = count + 1
logme("Processing " .. file )
logme("Getting " .. file )
logcontent = getlogfile(source, cookiesfile, file)
logentries = parsedglog(logcontent)
importdglog(logentries, source.sourcename)
logme("Deleting " .. file )
deletelogfile(source, cookiesfile, file)
importlogfile(source, cookeisfile, file, parsedglog, importdglog)
elseif string.match(file, "squid/access%.log[%.%-]") then
count = count + 1
logme("Processing " .. file )
logme("Getting " .. file )
local logcontent = getlogfile(source, cookiesfile, file)
local logentries = parsesquidlog(logcontent)
importsquidlog(logentries, source.sourcename)
logme("Deleting " .. file )
deletelogfile(source, cookiesfile, file)
importlogfile(source, cookeisfile, file, parsesquidlog, importsquidlog)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment