In our Angular app (made with Angular CLI) we use several console
statements. Is there a global way to detect environment and then display console.log
in our components and service only under development?
What I mean by global way - I know we can use something like:
if (!environment.production) { console.log(this.reviewTasksList); }
But by using this code everytime we have to console.log
(along with necessary import to get environment
variable) our code will become kind of verbose.
I want to know if there is a way to maybe:
Or the better solution here is to create a logger service and do all the environment check within it?
I don't want my bundle size to be impacted by debug statements and service.
Programmers frequently use console. log to record errors or other informational messages in their Angular applications. Although this is fine while debugging your application, it's not a best practice for production applications.
This doesn't strip console. log. It simply changes console.
AngularJs includes logging service $log, which logs the messages to the browser's console. The $log service includes different methods to log the error, information, warning or debug information. It can be useful in debugging and auditing.
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 () { }; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With