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.

Log / info methods don't respect metadata overrides

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v10.14.2
  • Operating System? (Windows, macOS, or Linux) Windows and Linux
  • Language? all

What is the problem?

If I create a root logger with some default metadata property and a format string containing metadata, then create a child logger, calling child.info('test') ignores the metadata set on the child. If I call child.log({ level: 'info, message: 'test' }) the metadata is honored.

I also noticed that this behavior is broken even on the root logger. If you use defaultMeta, it will overwrite data in your info object.

What do you expect to happen instead?

I expect the child behave consistently when calling .log and .info

Other information

There seem to be a few problems here.

First Problem: When you create a logger with default metadata, it is stored as defaultMeta. When you call log(info), the default metaData is applied onto info, effectively overwriting whatever you passed.

logger.log({ level: 'debug', message: 'root log', component: 'ROOT2' });
// => [debug][ROOT]: root log
_addDefaultMeta(msg) {
    if (this.defaultMeta) {
      Object.assign(msg, this.defaultMeta); // msg gets overwritten with defaultMeta
    }
  }
}

this function should probably assign in reverse order to a blank object and return the value…

Second Problem: When calling .info(), the same happens:

  logger.info({ message: 'root info', component: 'ROOT2' });
 // => [info][ROOT]: root info

Third Problem: When creating a child logger which overrides component, if you call .info on the child, the metadata from the root is used instead. This is because the child() method only overrides write()

Please let me know if you need a full reproduction. I can try to provide one.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
pciazynskicommented, Jan 7, 2020

This bug is affecting me as well. The problem is, that I cannot overwrite defaultMeta.

2reactions
maverick1872commented, Feb 19, 2019

I have created a PR that I believe will address your issue, as well as mine @kbirger. Please test it and let me know if it does not function as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LogHandler Protocol Reference - Apple
A LogHandler is an implementation of a logging backend. ... this must not override `logger1`'s metadata XCTAssertEqual(.debug, logger1.
Read more >
HD Data Override: Advanced Metadata - Akamai TechDocs
This behavior specifies ​Akamai​ XML metadata. Unlike the Advanced behavior, this one may apply a different set of overriding metadata that executes in...
Read more >
Complete Winston Logger Guide With Hands-on Examples
A logger offers many benefits over any type of manual logging techniques, such as the good old console.log . Winston offers: ...
Read more >
Suppress all Logback output to console? - Stack Overflow
LoggerAction - Setting additivity of logger [ch.qos.logback] to false 13:39:20 ... You may or may not have to override other methods } public...
Read more >
Swift Logging - NSHipster
We can override this behavior to instead write to standard error ( stderr ) ... Notice that the messages logged with the trace...
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