DEV Community

Discussion on: Say Goodbye to console.log from Production environment

Collapse
 
greenchapel_john profile image
greenchapeljohn

That’s nice and simple on Next.js.
On Angular I created a service for logging and the log level is set based on what environment you log too. I then like to use the linter to stop any uses of console.log in the code ( except in the service ) a good git hook running the lint then stops people from committing a console log in the code.

One advantage I get with this is based on the error the service can decide if it wants to send the log via REST API to an external service for monitoring.

Collapse
 
gulshanaggarwal profile image
Gulshan Aggarwal

Oh! making something cool is very hard but you did it, hats off you man.

Collapse
 
frontendplace profile image
Ron Jonk • Edited

And then y can check a session variable to either show or hide the logs on production is also possible. It will be very difficult in your minified code to find that needed session variable to set the log.level. Show default the loglevel “error” and not “ debug” and with the session variable set y can show all “debug” level logs