# Best way to toggle between enabled and disabled console logs?

**URL:** <https://community.postman.com/t/best-way-to-toggle-between-enabled-and-disabled-console-logs/20231>\
**Category:** Help Hub\
**Created:** [February 9, 2021, 7:23pm UTC](https://community.postman.com/t/best-way-to-toggle-between-enabled-and-disabled-console-logs/20231 "2021-02-09T19:23:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dereklowery](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@dereklowery](https://community.postman.com/u/dereklowery)\
**Post date:** [February 9, 2021, 7:23pm UTC](https://community.postman.com/t/best-way-to-toggle-between-enabled-and-disabled-console-logs/20231/1 "2021-02-09T19:23:23Z")

</div>

Scenario: I have a collection with multiple requests and within each request there are numerous console.log lines that write out variable names/values creating a detailed trace of what is going on. With the amount of data I’m looping through and writing out to the console, postman becomes very sluggish (Which I expect given how much is writing out).

What would be the best way to conditionally toggle logging on/off? I like the idea of having all of the logging for trace and troubleshooting purposes, but I don’t want it enabled full time.

The only thing I can think of is set a postman variable e.g. “EnableConsoleLog” and give it a true/false value.

Then within my scripts use an if conditional to check that variable value to determine whether or not my console.log line gets hit or not.

Is there a cleaner or better approach to doing this?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 10, 2025, 10:16am UTC](https://community.postman.com/t/best-way-to-toggle-between-enabled-and-disabled-console-logs/20231/2 "2025-04-10T10:16:16Z")

</div>

Sorry we didn’t get to this sooner. This isn’t the experience we want for our users.

Not the most elegant of solutions but something like this could work, it could be placed at the Collection level or in the [Package Library](https://learning.postman.com/docs/tests-and-scripts/write-scripts/package-library/). It’s checking if the `EnableConsoleLog ` variable is present rather than if it’s a particular value and then turning on/off logging.

```auto
let EnableConsoleLog = pm.environment.has("EnableConsoleLog") ? true : false;

function logMessage(message, EnableConsoleLog) {
    if (EnableConsoleLog) {
        console.log(message);
    }
}

logMessage('This is a log message', EnableConsoleLog);

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 10, 2025, 10:16am UTC](https://community.postman.com/t/best-way-to-toggle-between-enabled-and-disabled-console-logs/20231/3 "2025-04-10T10:16:21Z")

</div>

Closed on April 10, 2025, 10:16am UTC


