Debugger tools

By stick I mean after saving the app, I close out and reopen the app code and have the folds that I set when saved still be there. I just tested this and everything was expanded again when I reopened the code.

Yeah, that's a bug... It will be fixed. Shortly. It will be browser specific and not saved with the app, BTW.

2 Likes

what are the command for go to line number? (or key sequence)?

Alt - G

thx, should get added to the help button with pc and mac options (on mac it is option-g)

Any plans to make a more standard debugging framework? It seems like having a standard way to call logger(msg,level) and to then set the level for a given App or Device would be appropriate versus every developer rolling (aka cut and pasting from this thread!) someone else's version of this. Alongside this, why not add a filter on the IDE to limit which level of message's I see?

1 Like

Old thread, but debugging is a universal topic. Just sharing what I've got, and I'll be looking around at other apps to see what improvements I can make.

I'm using a "logTrace" function (though "logTrace" was a poor choice), with four parameters for a parent app and three for child/stand-alone apps.

logTrace(line number, log message, log type, child app name)
Example:

logTrace(896,"Invalid value for action \"$action\" sent to widget function","error",childAppLabel)

logTrace(919,"Device $device turned on","info")

Master function:
def logTrace(lineNumber,message = null, type = "trace",childLabel = "Master"){
// Uncomment return for no logging at all
// return

    // logLevel sets number of log messages
    // 1 for least (errors only)
    // 5 for most (all)
    logLevel = 5
    
    message = (message ? " -- $message" : "")
    if(childLabel != "Master") message = "[$childLabel]$message"
    if(lineNumber) message = "(line $lineNumber) $message"
    message = "Master $message"
    switch(type) {
        case "error":
        log.error message
        break
        case "warn":
        if(logLevel > 1) log.warn message
        break
        case "info":
        if(logLevel > 2) log.info message
        break
        case "trace":
        if(logLevel > 3) log.trace message
        break
        case "debug":
        if(loglevel == 5) log.debug message
    }
    return true
}

Child app function:
def logTrace(lineNumber,message = null, type = "trace"){
// Uncomment return for no logging at all
// return

     // logLevel sets number of log messages
    // 1 for least (errors only)
    // 5 for most (all)
    logLevel = 5

    message = (message ? " -- $message" : "")
    if(lineNumber) message = "(line $lineNumber)$message"
    message = "$app.label $message"
    switch(type) {
        case "error":
        log.error message
        break
        case "warn":
        if(logLevel > 1) log.warn message
        break
        case "info":
        if(logLevel > 2) log.info message
        break
        case "trace":
        if(logLevel > 3) log.trace message
        break
        case "debug":
        if(loglevel == 5) log.debug message
    }
    return true
}

Of course, they could be merged together, and have the child apps call the parent log function, but I think it's cleaner to have each child app do their own logging.

I do wish there were some sort of integrated testing tools, and a better logging system. Even just having the line number.... what a difference that would make! Even if the testing tool were a sandbox system like @krlaframboise's link. I just find it hard to believe that in-house Hubitat developers are doing this kind of ad hoc debugging. If that's true they have an in-house debug tool (speculation) , they could open it to trusted/known developers (not to say I'm either).

We are, though none of us leave anything like the levels of debug code you suggest embedded in the production code.

We dont...

Fair enough! I'll strike that part of my post :slight_smile:

edit: And I always forget how transparent you guys are! I speculate rather than ask, since I figure it's useless to ask for insider info. Love it!