FiringBlanks
FiringBlanks

Reputation: 2084

Change console.log() for production deployments?

I'm outputting a lot a internal info through extensive use of console.log(). Is there a way to change the .log() command for my --prod builds in Angular?

Upvotes: 1

Views: 1970

Answers (2)

FiringBlanks
FiringBlanks

Reputation: 2084

Building off of Yash Rami's answer, I found that I needed to use window.console.log() in main.ts.

if(environment.production){
    window.console.log = function() {}
    enableProdMode();
}

Upvotes: 4

Yash Rami
Yash Rami

Reputation: 2327

you need to write this in main.ts. I hope it helps you out

      import { enableProdMode } from '@angular/core';
      import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
      import { AppModule } from './app/app.module';
      import { environment } from './environments/environment';

      if (environment.production) {
        console.log = function() {}   // this will be disable all the logs in production mode 
        enableProdMode();
      }

      platformBrowserDynamic().bootstrapModule(AppModule)
      .catch(err => console.log(err));

Upvotes: 1

Related Questions