Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging in production best practice?

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?

like image 409
Terry Djony Avatar asked Dec 14 '17 13:12

Terry Djony


People also ask

What should be logging level in production?

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.

What are the five levels of logging?

Logging levels explained. The most common logging levels include FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL, and OFF.

What are logs in production?

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.


1 Answers

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.

like image 176
Kaloyan Kosev Avatar answered Sep 28 '22 09:09

Kaloyan Kosev