Angular console log only on development environment

Alternatively you can use a common service to achieve this

this.loggerService.log(this.reviewTasksList);

where as in your service you can use

log(text: string){
     if (!environment.production) {
       console.log(text)
     }
}

You can use isDevMode() or your environment.production to check if the code runs in development or production mode.

I think a logger service would be a good idea and then register a different logger service in providers depending on the mode.

See also https://github.com/angular/angular/pull/14308


This overwrites all console logs with blank function.

if (environment.production) {
  enableProdMode();
  window.console.log = function () { };   // disable any console.log debugging statements in production mode
  // window.console.error = function () { };

}

what if you override console.log if it's not in dev mode ?

 if (! isDevMode()){
   console.log = (...args)=>{}
 }

Tags:

Angular