All files / services logger.js

100% Statements 11/11
100% Branches 0/0
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421x 1x 1x   1x 1x 4x   1x                                                     1x 1x   2x      
const {createLogger, format, transports} = require('winston');
require('winston-daily-rotate-file');
const config = require('../server/config');
 
const {combine, timestamp, printf} = format;
const logNameBase = `${config.logger.applicationName}-${config.logger.environment}`;
const myFormat = printf(info => `${info.timestamp} - ${info.level}: ${info.message}`);
 
const logger = createLogger({
  transports: [
    new transports.Console({
      level: 'debug',
      format: combine(timestamp(), myFormat),
      colorize: true
    }),
    new transports.DailyRotateFile({
      name: 'info',
      format: combine(timestamp(), myFormat),
      filename: `${config.logger.logDir}%DATE%-${logNameBase}-info.log`,
      datePattern: 'YYYY-MM-DD',
      level: 'debug',
      zippedArchive: true,
      maxDays: config.logger.logStoringDays
    }),
    new transports.DailyRotateFile({
      name: 'error',
      format: combine(timestamp(), myFormat),
      filename: `${config.logger.logDir}%DATE%-${logNameBase}-error.log`,
      datePattern: 'YYYY-MM-DD',
      level: 'error',
      zippedArchive: true,
      maxDays: config.logger.logStoringDays
    })
  ]
});
module.exports = logger;
module.exports.stream = {
  write(message) {
    logger.debug(message.trim());
  }
};