Node.js REST Service Logging - createLogger.js - 2
Fri Apr 14 2023 10:43:00 GMT+0000 (Coordinated Universal Time)
Saved by
@mindplumber
#javascript
#nodejs
const createCategoryLogger = require('./createLogger');
const appLogger = createCategoryLogger('app');
const adminLogger = createCategoryLogger('admin');
const userLogger = createCategoryLogger('user');
content_copyCOPY
In this updated version of the `createLogger.js` file, we've added the `getLogFileName` function to generate log file names with timestamps. We've also parameterized the logger setup to accept a `category` parameter and create a logger instance for that category. Finally, we've updated the logger configuration to log messages in JSON format.
With these modifications, we can now create logger instances for different categories with the following code
Comments