Toggle Logging in an app

Can excessive logging have a negative effect on the hub? If so, is there a way to turn logging on and off within a custom app?

Excessive logging may have an adverse effect, but if it's just verbose and not truly excessive (I'm being vague here because I don't know if anyone knows the exact limits), I think the biggest problem is the inability to track down past logs (it only save so many) when you're trying to track down a particular issue.

As for custom apps, many developers include the option to toggle this logging. If it's your own app, you can certainly do this too--or I guess since it's custom code, you can modify it regardless. :slight_smile:

Is there a simple way to do that?

Comment out any log.debug or any log.* line in the custom code.

I was kind of hoping for a toggle in the app that would enable and disable logging as needed. :slight_smile:

Yeah, the author of the code would have to do that.

I could add it, but the only way I know to do it is to ad an if statement where ever there is a log.trace or such that says if toggle is on then show log. Is there a better way to do it?

You can add a log method. Def loggger(evt) { if logOn log.debug evt }

Or similar. And then just logger("log this") instead of log.debug "log this"

2 Likes

Hubitat supplies sample code, as you know, at their github. I grabbed a chunk of code that acts as a reminder for when I need to add it to custom code...

preferences {
    input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
    input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true

> def updated() {
>     unschedule()
>     if (debugOutput) runIn(1800,logsOff)
> 
> def logsOff(){
>     log.warn "debug logging disabled..."
>     log.warn "description logging is: ${txtEnable == true}"
>     device.updateSetting("debugOutput",[value:"false",type:"bool"])
> }
> 
> //  change log.debug to logDebug THEN add this (which has a needed log.debug)
> 
> private logDebug(msg) {
> 	if (settings?.debugOutput || settings?.debugOutput == null) log.debug "$msg"
> }
> 
> if (txtEnable) log.info

at the bottom of the preferences section, add the line for the toggle.

In the updated method, after an unsubscribe, add the runIn(1800 line (auto shuts debug in 30 mins.)

Add the logsOff method

Then change every occurrence of "log.debug" to logDebug

THEN add the private logDebug method (it will be the only 'legitimate' log.debug in the entire code.

For an APP... change:
device.updateSetting("debugOutput",[value:"false",type:"bool"])
to
app?.updateSetting("debugOutput",[value:"false",type:"bool"])

1 Like

I actually didn't know. I haven't done a ton of developing on HE so it never occurred to me to look there. Thanks!

Hi @patrick,
How do you subscribe to such an evt. handler? Thank you.