Logging. Server and Application

The log is what appears on the console of the server when we run an Express application. It may be saved in a log file too, so that we may study the content at a later time. The log is meant to tell us what happened when …

In our work with node and Express we have implicitly included the

const logger = require('morgan');
        // more code ...
app.use(logger('dev'));

where line 1 gets access to the morgan middleware for logging, and line 3 assigns the option dev to the logging process. The standard question we have to ask as developers is how much to log? Take a close look at the morgan documentation where you in the Options section will find a description of the possibilites. The general consensus is that in development we need more on log for debugging purposes, than we do in a production environment. Otherwise the answer is dependent on the customs and policies of the installation owning the Express application.

The documentation referred to in the link above also has examples that demo writing the log to a file. You may say that an application is a prototype at least until there's persistence of logs. Study it carefully, and choose a mode for your applications. Especially the rotation of logs so that any individual log does not get too big.

Logging is the borderline between system administrators and developers, but as the developer you must reflect the policy the system administrator is responsible for.