All files / src logging.utils.ts

100% Statements 6/6
50% Branches 1/2
100% Functions 2/2
100% Lines 6/6

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 281x 1x 1x   1x 3x             64x                              
import winston, { format } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file'
const { errors  } = format;
 
export function createLogger(service:string) {
  return winston.createLogger({
    level: 'debug',
    format: winston.format.combine(
      errors({ stack: true }),
      winston.format.timestamp({
        format: 'YYYY-MM-DD HH:mm:ss'
      }),
      winston.format.printf(info => `[${info.timestamp}] [${info.service}] [${info.level}]: ${info.message}`+(info.splat!==undefined?`${info.splat}`:" "))
  ),
    defaultMeta: { service },
    transports: [
      new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
      new DailyRotateFile({
        filename: 'logs/combined-%DATE%.log',
        datePattern: 'YYYY-MM-DD',
        zippedArchive: true,
        maxSize: '20m',
        maxFiles: '14d'
      }),
      new winston.transports.Console({}),
    ],
  });
}