TrimAgency / bot-starter

0 stars 0 forks source link

Add Winston #9

Open sgilliam15 opened 4 years ago

sgilliam15 commented 4 years ago

yarn add winston yarn add @types/winston


import * as winston from 'winston';

export const createWinstonLogger = () => {
  const alignColorsAndTime = winston.format.combine(
    winston.format.colorize({
      all: true,
    }),
    winston.format.label({
      label: '[LOGGER]',
    }),
    winston.format.timestamp({
      format: 'YY-MM-DD HH:MM:SS',
    }),
    winston.format.printf((info) => ` ${info.label}  ${info.timestamp}  ${info.level} : ${info.message}`),
  );

  const logger = winston.createLogger({
    level: 'info',
    format: winston.format.combine(
      winston.format.colorize(),
      winston.format.metadata({ fillExcept: ['message', 'level', 'timestamp', 'label'] }),
      alignColorsAndTime,
    ),
    transports: [
      new winston.transports.Console(),
      new winston.transports.File({
        filename: 'info.log',
      }),
    ],
  });
  return logger;
};```