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.

winston.transports.DailyRotateFile is not a constructor

See original GitHub issue

When I try the example setup, I run into an exception.

var winston = require('winston');
winston.cli();

var transport = new (winston.transports.DailyRotateFile)({
    filename: 'logs/log',
    datePattern: 'yyyy-MM-dd.',
    prepend:true,
    level: "verbose",
    maxDays:0
});

winston.add(transport);

Gives me:

TypeError: winston.transports.DailyRotateFile is not a constructor at Object.<anonymous> (/home/project/Backend/node-server/logger.js:8:17) at Module._compile (module.js:570:32) at Object.Module._extensions…js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/project/Backend/node-server/server.js:3:14) at Module._compile (module.js:570:32)

Node Version v6.10.3 NPM Version 3.10.10 Winston 2.3.1 Winston-Daily-Rotate-File 1.7.0

Running on Ubuntu 16.04.3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
mgaracommented, Jul 2, 2019

Hello Does this work ?

const { format, createLogger, addColors, transports: winstonTransports } = require('winston');

require('winston-daily-rotate-file');

  const rotateFileTransport = new (winstonTransports.DailyRotateFile)({
      filename: FILE_ROTATION_FILENAME,
      datePattern: 'YYYY-MM-DD',
      prepend: true,
      zippedArchive: true,
      json: false,
      level: LOGGING_LEVEL
    });

    transports.push(rotateFileTransport) // transports is an array passed to the logger instance

Becasue my code is triggering the exact same issue here …

winston : 3.2.1
winston-daily-rotate-file : 3.9.0

Update and if you came here from google : Solution is @ #205

import { createLogger, transports } from "winston";
import DailyRotateFile = require("winston-daily-rotate-file");

const logger = createLogger({
    transports: [
        new DailyRotateFile({
        })
    ]
});

1reaction
mattberthercommented, Sep 14, 2017

I dont see require('winston-daily-rotate-file');

What happens with:

var winston = require('winston');
require('winston-daily-rotate-file');
winston.cli();

var transport = new (winston.transports.DailyRotateFile)({
    filename: 'logs/log',
    datePattern: 'yyyy-MM-dd.',
    prepend:true,
    level: "verbose",
    maxDays:0
});

winston.add(transport);
Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS Logger: winston.transports.DailyRotateFile is not a ...
I'm trying to do so with winston.transports.DailyRotateFile. A piece of code below. api.use(expressWinston.logger({ 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 >
winston.transports.DailyRotateFile is not a constructor
I am not sure what I'm doing wrong here. Any help is appreciated. var winston = require('winston'); require('winston-daily-rotate-file'); ...
Read more >
winston.Transports.DailyRotateFile JavaScript and Node.js ...
const File = config.rotate ? winston.transports. ... DailyRotateFile(Showing top 5 results out of 315) ... Internals/Logger.js/undefined/constructor.
Read more >
Node.js Logging with Winston - Reflectoring
Winston Transports. Transports is a Winston feature that makes use of the Node.js networking, stream, and non-blocking I/O properties. Transport ...
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