Blog on software engineering
Using ‘winston-daily-rotate-file in TypeScript

Using ‘winston-daily-rotate-file in TypeScript

 

In TypeScript you need to import the library ‘winston-daily-rotate-file’ like, so:

 

import ‘winston-daily-rotate-file’

 

import { createLoggerformatLoggertransports } from ‘winston’;

import ‘winston-daily-rotate-file’;

 

let _winstonLoggerLogger;

 

function initialise() {

  _winstonLogger = createLogger({

    format: format.json(),

    transports: [

      new transports.Console({

        format: format.combine(format.colorize(), format.simple()),

      }),

    ],

  });

}

 

function addRotatingFileSystemLogging() {

  const options = {

    filename: ‘application-%DATE%.log’,

    datePattern: ‘YYYY-MM-DD’// Rotate every day

    zippedArchive: true,

    maxSize: ’20m’,

    maxFiles: ’31d’

  };

 

  const transport = new transports.DailyRotateFile(options);

  _winstonLogger.add(transport);

}

 

<

p style=”background: #1e1e1e”>
 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.