Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]: Wintson logs "undefined" in production env #2449

Open
artemkopytko opened this issue Apr 17, 2024 · 1 comment
Open

[Bug]: Wintson logs "undefined" in production env #2449

artemkopytko opened this issue Apr 17, 2024 · 1 comment

Comments

@artemkopytko
Copy link

artemkopytko commented Apr 17, 2024

🔎 Search Terms

undefined, production, env

The problem

Here's my logging class. Everything works perfect on development env. As soon as I set NODE_ENV=production - winston ignores any message passed and just prints "undefined" to the log file

Undefined is being logged on production env:
Screenshot 2024-04-16 at 22 52 56

When .env is any other from "production" - all works fine, as it should be

What version of Winston presents the issue?

v3.12.1

What version of Node are you using?

v16.14.2

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

import winston from 'winston';
import path from 'path';
import DailyRotateFile from 'winston-daily-rotate-file';

export class Logger {
  private static _instance: Logger;
  private logger: winston.Logger;
  private rotateFileConfig = {
    datePattern: 'YYYY-MM-DD',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d',
  };

  private infoTransport: DailyRotateFile = new DailyRotateFile({
    level: 'info',
    filename: path.resolve(__dirname, '..', '..', 'logs', '%DATE%.info.log'),
    ...this.rotateFileConfig,
  });

  private constructor() {
    this.logger = winston.createLogger({});

    if (process.env.NODE_ENV !== 'production') {
      this.logger.add(
        new winston.transports.Console({
          format: winston.format.combine(
            winston.format.colorize(),
            winston.format.simple(),
          ),
        }),
      );
    } else {
      this.logger.add(this.infoTransport);
    }

    this.logger.on('error', (err) => {
      console.error('Logger error:', err);
    });
  }

  static getInstance() {
    if (this._instance) {
      return this._instance;
    }

    this._instance = new Logger();
    return this._instance;
  }

  public async logInfo(message: string) {
    this.logger.log({
      level: 'info',
      message: message,
    });
  }
}

Additional information

No response

@CSirolliTownleyIT
Copy link

Seems like an issue with winston-daily-rotate-file, and looks like a similar issue as in winstonjs/winston-daily-rotate-file#249.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants