How can I make logs (INFO, ERROR) dependent on set NODE_ENV?
I mean, for example, if NODE_ENV=development, I write only ERROR logs. With NODE_ENV=production, there has to be only INFO.
How should I modify appenders to perform this?
Thanks for your help.
With Log4js it looks like you just need to set the level on the logger depending on the environment variable, e.g.
var logger = log4js.getLogger('myLogger');
if (process.env.NODE_ENV === 'production') {
logger.setLevel('ERROR');
} else {
logger.setLevel('INFO');
}
Note that I switched your log levels around as how most logging works you want increasing levels of severity with ERROR being more serious than INFO. In production you want only the most serious errors to be logged. In development you want to see serious errors as well as logs that are just for information.
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