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.

Message not encoded on 'info' object using triple-beam

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs:
  • Operating System? (Windows, macOS, or Linux)
  • Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart)

What is the problem?

In the Console transport, the message is read from the info object with the following logic:

const { LEVEL, MESSAGE } = require('triple-beam');
...
  log() {
    ....
    console._stderr.write(`${info[MESSAGE]}${this.eol}`);

The problem is that the message is placed on the info object using a standard 'message' string key:

      this.write({ [LEVEL]: level, level, message: msg });

What do you expect to happen instead?

Shouldn’t the message be placed on the info object using the triple-beam MESSAGE symbol?

      this.write({ [LEVEL]: level, level, [MESSAGE]: msg, message: msg });

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
GeeWeecommented, May 21, 2019

This is crazy confusing behaviour - I just spent a few hours debugging this. Let me provide an example:

const customFormat = winston.format((info, opts) => {
  info.message = 'my less cool message';
  return info;
});

// Example of using a custom format taken from 
// https://github.com/winstonjs/winston#formats
const requestLogger = winston.createLogger({
  level: 'debug',
  // format: winston.format.simple(),
  format: winston.format.combine(
    winston.format.label({ label: 'right meow!' }),
    winston.format.timestamp(),
    customFormat(),
    // note no finalizing format, but there isn't in the docs either!
  ),
  transports: [
    new winston.transports.Console()
  ]
});

This simply logs undefined, when according to the docs it should work. I spent a few hours before finding out you have to set info[MESSAGE] with the symbol from triple-beam. I think we should log an error if there’s no info[MESSAGE] and document that you have to finish with a “finalizing logger” - there’s no real mention of them in the docs.

Edit: Looking at it, I see that instead of using winston.format to create the custom format, it’s using printf. Perhaps all you need is some documentation in the implementing custom format docs then.

0reactions
indexzerocommented, Jan 26, 2019

This is something we should consider, but it is currently by design. This is a corner case where someone has opted to not include a “finalizing formats”:

  • json
  • logstash
  • printf
  • prettyPrint
  • simple

All of these would set the MESSAGE symbol for you. Does that make sense @jd-carroll?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Triple Beam Balance
Triple beam balance. Instructions on use. The triple beam balance is used to measure masses very precisely; the reading error is 0.05 gram....
Read more >
Cognitive psychology book notes
Inattentional blindness is a failure to perceive an unattended object because its features were not successfully bound by attention.
Read more >
Third Party Licenses
... @aws-sdk/util-hex-encoding; @aws-sdk/util-locate-window ... has-unicode; hosted-git-info; icss-replace-symbols; icss-utils; idb; ignore-by-default ...
Read more >
Base station beam sweeping method and apparatus using ...
A method and apparatus for wireless communications wherein a base station transmits and receives wireless signals through multiple directional antennas ...
Read more >
Science Prep Test #1 Flashcards
C - Sending messages about the correct sequence of proteins in DNA ... A - DNA carries genetic information from RNA to the...
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