question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DailyRotateFileTransport class is not a constructor

See original GitHub issue
import winston, { format } from 'winston';
import 'winston-daily-rotate-file';
const { combine, timestamp, prettyPrint } = format;

const logger = winston.createLogger({
  format: combine(
    timestamp(),
    prettyPrint()
  ),
  transports: [
    new winston.transports.DailyRotateFileTransport({
      dirname: './logs/errors',
      filename: 'error.%DATE%.log',
      datePattern: 'HH:mm'
    })
  ]
});

Whether I declare a transport object of DailyRotateFileTransport class, I get an error

new winston_1.default.transports.DailyRotateFileTransport({
^

TypeError: winston_1.default.transports.DailyRotateFileTransport is not a constructor

Could you tell me if it happens because of using typescript or there is another reason?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
JE-leecommented, Apr 1, 2021

you shoule chage the import statement .

import * as winston from 'winston';
import 'winston-daily-rotate-file';
import { WinstonModule } from 'nest-winston';

export function getWinstonModule() {
  const transport = new winston.transports.DailyRotateFile({
    filename: 'application-%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d',
  });

  transport.on('rotate', function (oldFilename, newFilename) {
    // do something fun
  });

  return WinstonModule.forRoot({
    transports: [transport],
  });
}

my winston-daily-rotate-file’ version is ^4.5.1.

1reaction
mykhailo-budishcommented, Nov 3, 2019

Im not at all familiar with typescript. That’s a question for @Slessi. However, what happens if you change winston.transports.DailyRotateFileTransport to winston.transports.DailyRotateFile?

The same thing. But I have found a solution in

import winston, { format } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';

const errorTransport = new DailyRotateFile({
  dirname: 'logs/errors',
  filename: 'error.%DATE%.log',
  datePattern: 'DD-MM-YYYY',
  level: 'error'
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS Logger: winston.transports.DailyRotateFile is not a ...
I had to do this so it would work: var winston = require('winston'), expressWinston = require('express-winston'); winston.transports.
Read more >
winston-daily-rotate-file - npm
A transport for winston which logs to a rotating file each day.. Latest version: 4.7.1, last published: 7 months ago.
Read more >
How to use Winston Daily Rotate File Logger in NodeJs
const transport = new (winston.transports. ... Winston daily rotate file ensure that we do not have all log being written in single file....
Read more >
Node.js Logging with Winston - Reflectoring
If we do not explicitly state our winston logging level, ... winston-daily-rotate-file is a transport maintained by winston contributors.
Read more >
Winston - Best of JS
transports, [] (No transports), Set of logging targets for info messages ... class YourCustomTransport extends Transport { constructor(opts) { super(opts); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found