Is it alright to use morgan as logger on production mode, or just throw it away and only use it on development mode?
What's the best practice for logging on production mode?
Logging levels are usually considered to be in order of importance: turn on "unimportant" levels in development ( trace , debug and the like), but enable only the "most important" levels ( warning , error , etc.) in production, where resources like CPU time and disk space are precious.
Logging levels explained. The most common logging levels include FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL, and OFF.
Production logs are used to evaluate fluid production and movement both inside and outside of the casing downhole. The production logging tools are small in diameter and are run through tubing for evaluation of the well as it is producing.
Yes! It is all right to use Morgan as a logger on production mode.
Arguably, if I can generalize to answer your question, the best practice in production is to log as many details as possible. The idea is that the logs on your server show you as much relevant information as you need. After all, you and the people with access to the server are the only one who sees them, right?
A strategy I use is a 'combined' mode in production, which is a bit more detailed, and a 'dev' mode in development, which is more concise.
You can switch those easily with environmental variable or whatever. Example:
if (app.get('env') === 'production') {
app.use(logger('combined'));
} else {
app.use(logger('dev'));
}
Another thing I always configure is writing the logs in an external file. Needless to say why this is a nice to have, in production.
That's it in terms of Morgan. If you are wondering about the best for logging in general, well, that's another question which is already answered.
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