Hide console logs in production
This library overrides the default console object, making it non-functional in a production environment.
npm install console-prod
Import at the root of your project
For Example, in a NextJS app, that'll be _app.js
.
// _app.js
import 'console-prod';
In Dev mode, the console
methods have their default behavior. In production, all methods are void functions and will do nothing.
import 'console-prod';
console.log('Wild fire on the ocean bed');
// => Wild fire on the ocean bed
import 'console-prod';
console.log('Wild fire on the ocean bed');
// =>
To override this behaviour and force logs in prod, use the console.prod
method. Which is a direct implementation of the default console object.
import 'console-prod';
console.prod.log('Wild fire on the ocean bed');
// => Wild fire on the ocean bed
Note: The above examples also goes for all other console methods e.g
warn
,error
,info
,table
, etc.
In a server environment, console methods are not affected and function just as the default console methods.