Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

padLevels warning appears in Winston@3 #1882

Closed
1 task
SirProdigle opened this issue Jan 25, 2021 · 8 comments
Closed
1 task

padLevels warning appears in Winston@3 #1882

SirProdigle opened this issue Jan 25, 2021 · 8 comments

Comments

@SirProdigle
Copy link

SirProdigle commented Jan 25, 2021

Please tell us about your environment:

  • _winston version?
    • winston@2
    • [ x] winston@3
  • _node -v outputs: v14.13.1
  • _Operating System: Linux
  • _Language: ES6

What is the problem?

padLevels warning ("Accessing non-existent property 'padLevels' of module exports inside circular dependency") appears when using Winston 3.3.3. Issue has been mostly related to Winston@2

What do you expect to happen instead?

padLevels does not occur

Other information

Logger is created as so

var appRoot = require('app-root-path');
var winston = require('winston');
const colorizer = winston.format.colorize();

// define the custom settings for each transport (file, console)
var options = {
    console: {
        handleExceptions: true,
        level: "info",
        format: winston.format.combine(
            winston.format.timestamp({format: "HH:mm:ss"}),
            winston.format.simple(),
            winston.format.printf(msg =>
                colorizer.colorize(msg.level, `${msg.timestamp} - ${msg.level}: ${msg.message}`)
            ),
        )
    },
};

// instantiate a new Winston Logger with the settings defined above
const logger = new winston.createLogger({
    transports: [
        new winston.transports.Console(options.console)
    ],
    exitOnError: false, // do not exit on handled exceptions
});

// create a stream object with a 'write' function that will be used by `morgan`
logger.stream = {
    write: function(message, encoding) {
        // use the 'info' log level so the output will be picked up by both transports (file and console)
        logger.info(message);
    },
};

module.exports = logger;

A line such as logger.info("NPM package " + viewEngineData.expressName + " installed") will cause the warning.
unsure if my Winston setup is wrong but seem to be using only Winston3 functions

@camdagr8
Copy link

camdagr8 commented Mar 1, 2021

I'm seeing this issue too on Node 14.15.5

@DavidCockerill
Copy link

Also getting this issue... any suggestions out there?

@Heliks
Copy link

Heliks commented Jul 23, 2021

Any workarounds for this?

@DavidCockerill
Copy link

Yeah, switch to Pino :(

@akhila9996
Copy link

Any solution for this issue?
I don't want to switch to another library.

@hlynbech
Copy link

hlynbech commented Oct 6, 2021

I can't reproduce the warning in a clean project where only [email protected] is installed, so the error is not in winston@3 itself. Also, winston@2 under node 14 does not trigger this warning either.

However, I can reproduce this error in a project where BOTH winston@2 AND winston@3 are included via different dependencies. 'padLevels' was removed from winston@3.

So I think the underlying issue could be conflicting versions of winston in your dependencies (or dependencies' dependencies).

@flotwig
Copy link

flotwig commented Nov 8, 2021

We also get this in [email protected]. This patch suppresses the warning:

diff --git a/node_modules/winston/lib/winston/common.js b/node_modules/winston/lib/winston/common.js
index 8ed9973..53cf4cd 100644
--- a/node_modules/winston/lib/winston/common.js
+++ b/node_modules/winston/lib/winston/common.js
@@ -32,7 +32,7 @@ exports.setLevels = function (target, past, current, isDefault) {
   }
 
   target.levels = current || config.npm.levels;
-  if (target.padLevels) {
+  if (target.hasOwnProperty('padLevels') && target.padLevels) {
     target.levelLength = exports.longestElement(Object.keys(target.levels));
   }
 

@davidrapin
Copy link

davidrapin commented Mar 7, 2022

I can confirm that this happened with [email protected] but is fixed with [email protected]

djey47 added a commit to djey47/cool-updown-legacy that referenced this issue Apr 14, 2023
djey47 added a commit to djey47/cool-updown-legacy that referenced this issue May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants