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.

defaultMeta ignored when using logger.log function but not in logger[level] functions

See original GitHub issue

Please tell us about your environment:

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

What is the problem?

When calling the function logger.log('debug', 'message') it seems to completely ignore defaultMeta, but calling functions like logger.debug does not

My createLogger

const logger = winston.createLogger({
  level: "debug",
  defaultMeta: { id: 'APP' },
  format: winston.format.combine(
    winston.format.colorize(),
    winston.format.timestamp({
      format: "YYYY-MM-DD h:mm:ss:SSS"
    }),
    winston.format.printf(
      info => `${info.timestamp} ${info.level}: [${info.id}] ${info.message}`
    )
  ),
  transports: [new winston.transports.Console()]
});

What do you expect to happen instead?

Given my createLogger setup above I expect both

logger.info("This is my info")

AND

logger.log("info", "This is my info")

to both print out this to the console:

2020-02-04 11:30:34:313 info: [APP] This is my info

However the latter (logger.log) prints this

2020-02-04 11:30:34:307 info: [undefined] Initializing web sockets  

Other information

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Faithfindercommented, Aug 12, 2021

Still the same on 3.3.3

1reaction
gioamatocommented, Dec 23, 2021

Same happening with profiling, the logger.profile() method ignores defaultMeta.

So is this actually an issue or the expected behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js: Winston: Can I add default meta data to all log ...
js for logging. I know I can add metadata individually to each log message but is there a way to specify a default...
Read more >
Log4j2 Example Tutorial - Configuration, Levels, Appenders
Notice that the propagation of log events up in the logger hierarchy is beyond this computation and it ignores the levels. But what...
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
In this tutorial, we will explain how to install, set up, and use the Winston logger in a Node.js application. We'll go through...
Read more >
logging — Logging facility for Python — Python 3.11.1 ...
The basic classes defined by the module, together with their functions, are listed below. Loggers expose the interface that application code directly uses....
Read more >
How to use the winston.transports.Console function in ... - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix ... Instantiate a new Winston Logger with...
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