juttle / winston-logrotate

Log rotating transport for Winston
Apache License 2.0
10 stars 8 forks source link

TypeError: winston.transports.Rotate is not a constructor #12

Open nengine opened 7 years ago

nengine commented 7 years ago

Could you help me see what I might be doing wrong here? Thanks.

const winston = require('winston');
const { format } = require('logform');

require('dotenv').config();
require('winston-logrotate');

var rotateTransport = new winston.transports.Rotate({
        file: 'application.log',
        keep: 5,
        compress: true
});
TypeError: winston.transports.Rotate is not a constructor
    at Object.<anonymous> (C:\Users\nash\wsclient\app.js:25:23)
ladariha commented 7 years ago

Do you have winston version 3.0.0 ? It looks like this module is not compatible with it, only with winston 2.x

lmacardoso commented 6 years ago

Hi,

Check this example:

var winston = require('winston');
var Rotate = require('winston-logrotate').Rotate;

var rotateTransport = new Rotate({
        file: __dirname + '/log/debug.log', 
        colorize: false,
        timestamp: true,
        json: false,
        size: '10m',
        keep: 5,
        compress: true
});

var rotateTransportException = new Rotate({
        file: __dirname + '/log/exceptions.log', 
        colorize: false,
        timestamp: true,
        json: false,
        size: '10m',
        keep: 5,
        compress: true
});

var logger = new (winston.Logger)(
{
  transports: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    rotateTransport
  ],
  exceptionHandlers: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    rotateTransportException
  ],
  exitOnError: false
});

for (var i = 0 ; i < 10; i++)
{
    logger.info('Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis Lapis ', i);
}
demmer commented 6 years ago

Note: This project needs a new maintainer as I am no longer actively developing or using this.

shiwang987 commented 5 years ago

Same issue