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

Winston logform library does not have a unified way to return formatted message #125

Open
losalex opened this issue Nov 12, 2021 · 0 comments

Comments

@losalex
Copy link

losalex commented Nov 12, 2021

The code sample const { level, message, ...meta } = info; described here does not always returns message consistently and may vary depending if format object was provided to winston.createLogger() or not. It appears that info parameter could also have an info[Symbol.for('message')] in addition to info.message field and those values are not the same:

  1. In case when no formatting is provided to winston.createLogger() constructor, the correct message indeed returned by info.message.
  2. When formatting is provided to winston.createLogger() constructor, the correct message will be in info[MESSAGE] field, while info.message contains non-formatted version of the message.

Given a fact that we don't have a way to see if formatting was provided for winston.createLogger() constructor or not, we cannot provide a deterministic approach to fetch correct message (e.g. we cannot count on info[MESSAGE] nor on info.message fields to determine where is a "right" message is).

The code which can be used to test the issue is:

const logger = winston.createLogger({
    level: LOG_LEVEL,
    format: winston.format.combine(
        winston.format.timestamp({format: 'YYYY-MM-DD HH:mm:ss,SSS'}),
        winston.format.printf(info => `${info.timestamp} |${info.level.toUpperCase()}| my-service -> ${info.message}`)),
    transports: [
        // Add custom transport here to intercept the info for debugging purposes
        //new SomeTransportLogging(), 
        new winston.transports.Console()
    ]
});
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

1 participant