Toggle Debugging? Looking for suggestions

Hey all,

The more and more I work with Postman I find myself creating lots of collections that can get quite elaborate.

One thing I find myself doing often is using the console.log statement to output values or in some cases request/response bodies.

Most of the time I dont want these log statements in general as we do a lot of automated runs via Jenkins and this is just unnecessary output in the logs.

Does anyone have a preferred way of adding in debugging in their calls?
I was thinking along the lines of adding in some toggle that I would enable at the start of my collection to tell it to output the console logs or not, however the refactor effort would be quite great if I were to do this.

Just looking to see if others have done something similar

Thx,Trent

Any solution that you may implement at this point would require a refactor to any of your collections that you would want to apply the solution to … no getting around it.

I haven’t had the need to implement this but you could set global variables to “true” or “false” for the level of console output you would require …

pm.globals.set("debug", false);
pm.globals.set("info", false);
pm.globals.set("trace", false);

I would set them in the globals.postman_globals.json instead so that I would be sure that the variables would always be set and ready for any and all my collections.

And in your POSTMAN javaScripts, you could have …

if ( pm.globals.get("debug") )
    console.log("This is a debug msg");
if ( pm.globals.get("info") ) 
    console.log("This is an info msg");
if ( pm.globals.get("trace") ) 
    console.log("This is a trace msg");

or combinations of the settings …

if ( pm.globals.get("info") || pm.globals.get("trace") ) 
    console.log("This is a msg that I really want to see ");

Hope this help.

1 Like

@dhoyt This is great, its kind of along the lines of what I was thinking but I do like your usage of the global variables.

thanks for the feedback.

~ trent

Glad to have helped !