How to properly Debug?

peterraeves
Mega Guru

I often see code like this

var debug = true;

if (debug) gs.print(msg);

if (debug) gs.info(msg);

Is there a specific reason why people don't use the GlideSystem instead? Like this

if (gs.isDebugging()) gs.print(msg);

Or maybe even shorter

gs.debug(msg);

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

FWIW, I often have distinct debugging in each of my script includes so I can debug them independent of each other (not get overwhelmed with debug output.) In those cases, I'll make an _debug function.



_debug : function(msg) {


        if (this.debug)


                  gs.debug(msg);


}



Then call it in various places as



this._debug(recordCount + ' records read');



I can then turn on and off the debug property in the script include with a property so I don't have to modify code in production to enable/disable debugging.


View solution in original post

9 REPLIES 9

Wow, I really need to stop getting up at 3AM and start getting more sleep. Thanks.



I'll argue that the "or" in that is somewhat independent of each other. I could have session debugging off, but the logging.verbosity set to debug and get no output. Does that mean isDebugging returns true? I could also have session debugging on and logging.verbosity set to none and receive no output. Does that return true? Inquiring minds want to know... I need to some quick testing to find out more.


This answer is... OR. If session debugging is on OR the scoped property is debug, then the function returns true. I'm not sure I see a value in it to be honest. Still consider the impact to the best practices (even though I don't own them any more.)



This was certainly educational... all before 7AM.


As for linking to the wiki instead of docs... Jive has an issue with deep linking (as evidence of your link to gs.isDebugging() taking me to the developer home page instead of the actual page.)


Inquiry made to our developer portal people about more info on gs.isDebugging().


Chuck Tomasi
Tera Patron

FWIW, I often have distinct debugging in each of my script includes so I can debug them independent of each other (not get overwhelmed with debug output.) In those cases, I'll make an _debug function.



_debug : function(msg) {


        if (this.debug)


                  gs.debug(msg);


}



Then call it in various places as



this._debug(recordCount + ' records read');



I can then turn on and off the debug property in the script include with a property so I don't have to modify code in production to enable/disable debugging.