Let's follow the steps below to add custom Morgan logging to our Express web server:
- First, we'll simply change our default Morgan logger configuration to use the short predefined logging style. We do that by simply changing the string value provided to our logger instance:
...var logger = require('morgan');...app.use(logger('short'));...
- After restarting our server, we will note that our log messages now have a new format in our console when we visit pages of our application.
- Next, let's add some custom logging to our /middleware/auth.js middleware. We will create a new logger method, in that it will configure a custom log token and return a custom log format. This logger will record the admin's role and session ID as ...