Page 3 of 3
Re: need a loop for reading messages for logging [Solved]
Posted: Sunday 07 July 2019 11:11
by waaren
pvklink wrote: ↑Sunday 07 July 2019 10:34
i understand the problem with value 1 and 2 now...when only write to domoticz and not to global i dont get something back...
so my local logging function has to split domoticz and global logging in two executing parts...?
Best to change line 56-59 in global_data.lua from
Code: Select all
for i, record in ipairs(messages) do
dz.log(record.log, dz.LOG_INFO)
newText = record.text .. lf .. newText
end
to
Code: Select all
for i, record in ipairs(messages) do
if record.log then dz.log(record.log, dz.LOG_INFO) end
if record.text then newText = record.text .. lf .. newText end
end
Re: need a loop for reading messages for logging
Posted: Sunday 07 July 2019 16:31
by pvklink
Yesss, thank you waaren , it works !! finally!
i struggled with:
- if logcode = 1 or logcode = 3 then
- if logcode <> 2 they did not work...
if logcode ~= 2 then WORKED! i thought that ~ can only be used with strings not numeric
Code: Select all
addMessage =
function(dz, item, info, message, messages,logcode)
local trigger
if item.isDevice then
trigger = ", Device: " .. item.name
elseif item.isTimer then
trigger = ", Timer: " .. item.trigger
elseif item.isVariable then
trigger = ", Variable: " .. item.name
else
trigger = ", Unknown trigger"
end
messages[#messages + 1] = {}
if logcode ~= 2 then
messages[#messages].log = 'scriptname: ' .. info.scriptName .. trigger .. ' ' .. message
end
if logcode ~= 1 then
messages[#messages].text = dz.time.rawDate .. ' ' .. dz.time.rawTime .. ' : ' .. message
--messages[#messages].text = dz.time.rawDate .. ' ' .. dz.time.rawTime .. ' : ' .. message .. '<br>'
end
return messages
end,
dumpMessages =
function(dz, messages)
local textDevice = dz.devices('timerlog')
local currentText = dz.globalData.mylogging
local newText = currentText
local lf = '<br>' --local lf = "\n" --local lf = "\r\n" --PVK \n of \r\n UITGEZET ANDERS werkt dashticz niet
local maxLines = 8
for i, record in ipairs(messages) do
if record.log then dz.log(record.log, dz.LOG_INFO) end
if record.text then newText = record.text .. lf .. newText end
end
dz.log(newText, dz.LOG_INFO)
if newText ~= currentText then
--lines = dz.utils.stringSplit(newText, lf) -- create lines table from newText string --PVK UITGEZET ANDERS werkt dashticz niet
--newText = table.concat(lines, lf, 1, (math.min(maxLines,#lines))) -- recreate newText string from first maxLines --PVK UITGEZET ANDERS werkt dashticz niet
textDevice.updateText(newText)
dz.globalData.mylogging = newText -- ADDED
end
end,