Fix missing lua trace lines from log

Fixes #2701
This commit is contained in:
emanuele-f 2019-07-03 16:37:24 +02:00
parent 0957bef845
commit 45ca04d713
3 changed files with 36 additions and 25 deletions

View file

@ -26,10 +26,10 @@ TRACE_CONSOLE = 0
TRACE_WEB = 1
function traceError(p_trace_level, p_trace_mode,p_message)
currentline = debug.getinfo(2).currentline
what = debug.getinfo(2).what
src = debug.getinfo(2).short_src
traceback = debug.traceback()
local currentline = debug.getinfo(2).currentline
local what = debug.getinfo(2).what
local src = debug.getinfo(2).short_src
local traceback = debug.traceback()
for str in (string.gmatch(traceback, '([^\n]+)')) do
traceback = str
@ -37,27 +37,27 @@ function traceError(p_trace_level, p_trace_mode,p_message)
for str in (string.gmatch(traceback, '([^/]+)')) do
traceback = str
end
i = 0
local i = 0
for str in (string.gmatch(traceback, '([^:][^ ]+)')) do
if (i == 0) then traceback = str end
i = i + 1
end
traceback = traceback:sub(1, string.len(traceback)-1)
filename = src
local filename = src
for str in (string.gmatch(src, '([^/]+)')) do
filename = str
end
date = os.date("%d/%b/%Y %X")
trace_prefix = ''
if (p_trace_level == TRACE_ERROR) then trace_prefix = 'ERROR: ' end
if (p_trace_level == TRACE_WARNING) then trace_prefix = 'WARNING: ' end
if (p_trace_level == TRACE_INFO) then trace_prefix = 'INFO: ' end
if (p_trace_level == TRACE_DEBUG) then trace_prefix = 'DEBUG: ' end
if ((p_trace_level <= MAX_TRACE_LEVEL) and (p_trace_level <= TRACE_LEVEL) )then
if (p_trace_mode == TRACE_WEB) then
local date = os.date("%d/%b/%Y %X")
local trace_prefix = ''
if (p_trace_level == TRACE_ERROR) then trace_prefix = 'ERROR: ' end
if (p_trace_level == TRACE_WARNING) then trace_prefix = 'WARNING: ' end
if (p_trace_level == TRACE_INFO) then trace_prefix = 'INFO: ' end
if (p_trace_level == TRACE_DEBUG) then trace_prefix = 'DEBUG: ' end
if (filename..':'..currentline ~= traceback) then
print('<b>'..date..' ['..traceback..'] ['..filename..':'..currentline..'] ' ..trace_prefix..p_message..'</b></br>')
else
@ -65,9 +65,11 @@ function traceError(p_trace_level, p_trace_mode,p_message)
end
elseif (p_trace_mode == TRACE_CONSOLE) then
if (filename..':'..currentline ~= traceback) then
io.write(date..' ['..traceback..'] ['..filename..':'..currentline..'] ' ..trace_prefix..p_message..'\n')
--~ io.write(date..' ['..traceback..'] ['..filename..':'..currentline..'] ' ..trace_prefix..p_message..'\n')
ntop.traceEvent(p_trace_level, traceback..'] [' .. filename, currentline, p_message)
else
io.write(date..' ['..filename..':'..currentline..'] ' ..trace_prefix..p_message..'\n')
--~ io.write(date..' ['..filename..':'..currentline..'] ' ..trace_prefix..p_message..'\n')
ntop.traceEvent(p_trace_level, filename, currentline, p_message)
end
end
end
@ -83,4 +85,4 @@ function resetTraceLevel()
TRACE_LEVEL = 1
end
--------------------------------
--------------------------------