GTM
GTM

Reputation: 634

How to disable debug logging based on $location.host?

I want to disable debug logging based on the host address. For instance, I want to keep debug logging for DEV and QA instances and disable console debug logs on productions. Currently, the way to disable debug logs is by using

$logProvider.enableDebug(false)

I want this call only on a specific URL and $location is not available where $logProvider is available.

Upvotes: 0

Views: 146

Answers (2)

gkalpak
gkalpak

Reputation: 48211

You can use plain old JS window.location.host. E.g.:

var listOfDebugEnabledHosts = [...];
app.config(function ($logProvider) {
  var host = window.location.host;
  var debugEnabled = listOfDebugEnabledHosts.indexOf(host) !== -1;
  $logProvider.debugEnabled(debugEnabled);
});

Upvotes: 1

Sunny R Gupta
Sunny R Gupta

Reputation: 5126

I would recommend using: https://github.com/sunnykgupta/jsLogger

Features:

  • It safely overrides the console.log. Takes care if the console is not available (oh yes, you need to factor that too.)
  • Stores all logs (even if they are suppressed) for later retrieval.
  • Handles major console functions like log, warn, error, info.
  • Is open for modifications and will be updated whenever new suggestions come up.

Disclaimer: I am the author of the plugin.

Upvotes: 0

Related Questions