What is the best way to do with log.debug messages for a production driver?
During development i use a lot of log.debug() messages to check what is going on.
Now that I hope to release a few I wonder what you normally do?
Delete them and restore them if you need to debug to fix errors?
Comment them out?
Or has someone made a preprocessor to remove them automatically for production version?
Instead of directly using log.debug or log.log, I pass my debug lines to a custom function, which then checks a global flag whether to print it or not. The flag can either a Boolean defined at the top of init or using a device.preferences.something if you want to be able to control it from the app.
-- log to the console if the verbose log setting is switced on
function console_log(device, message, log_level)
if(device.preferences.verboseLog == true) then
if(log_level == nil) then log_level = 'debug' end
log.log({}, log_level, message)
end
end
Can’t say for certain unfortunately. Writing for ST Edge has been my first experience of Lua. This was just my best solution when faced with the same issue, but no doubt someone will have something better.