Page 1 of 1

variable logging

Posted: Saturday 16 January 2021 18:45
by pvklink
Is this possible ?, to make the logging variable by a selector switch?
when this works i will put this in a global function

error
2021-01-16 20:50:43.092 Error: dzVents: Error: (3.1.1) ...icz/scripts/dzVents/generated_scripts/DZ_schakelklok.lua:61: attempt to call a nil value (field 'devices')

Code: Select all


local function get_logtype()    
    if (domoticz.devices('logtype').state == 'info') then       --(rule 61)
        local logtype = domoticz.LOG_INFO
    elseif (domoticz.devices('logtype').state == 'error') then
        local logtype = domoticz.LOG_ERROR
    elseif (domoticz.devices('logtype').state == 'debug') then
        local logtype = domoticz.LOG_DEBUG
    elseif (domoticz.devices('logtype').state == 'exec') then
        local logtype = domoticz.LOG_MODULE_EXEC_INFO
    end
    return logtype
end
return 
{
    on ={timer = get_active_timers(Timers),},
    logging ={level   = get_logtype()},
    execute = function(dz,item,info)
    
 

Re: variable logging  [Solved]

Posted: Sunday 17 January 2021 0:28
by waaren
pvklink wrote: Saturday 16 January 2021 18:45 Is this possible ?, to make the logging variable by a selector switch?
Yes, but not like you coded it.

This should work.

Code: Select all

local function get_logtype(domoticz)
    if (domoticz.devices('logtype').state == 'info') then
        return domoticz.LOG_INFO
    elseif (domoticz.devices('logtype').state == 'error') then
        return domoticz.LOG_ERROR
    elseif (domoticz.devices('logtype').state == 'exec') then
        return  domoticz.LOG_MODULE_EXEC_INFO
    end
    return domoticz.LOG_DEBUG
end

return
{
    on =
    {
        timer =
        {
            'every minute',
        },
    },

    execute = function(dz,item,info)
        _G.logLevel = get_logtype(dz)
        dz.log('debug test',dz.LOG_DEBUG) -- this will only make it to the log when LOG_DEBUG is set
        dz.log('blabla',dz.LOG_FORCE) -- this will allways make it tp the log
    end
}

Re: variable logging

Posted: Sunday 17 January 2021 9:46
by pvklink
Ok, Thanks!
I am almost there to config my different kinds of logs and messages from within the userinterface (dashticz) with a selector.

Re: variable logging

Posted: Sunday 17 January 2021 15:49
by pvklink
everything works PERFECT !!

many thanks...(@waaren)