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

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

Closed
1 of 2 tasks
FranciscoG opened this issue Feb 4, 2020 · 8 comments
Closed
1 of 2 tasks
Assignees
Labels

Comments

@FranciscoG
Copy link

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

@alvinalexander
Copy link

alvinalexander commented Apr 10, 2020

I ran into the same issue. I believe this issue is related to this line:

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

@IzaacJ
Copy link

IzaacJ commented Jun 9, 2021

I have the same issue.
winston version: 3.3.3
node version: 16.2.0
Operating System? Windows 10 20H2
Language? TypeScript 4.3.2

@peey
Copy link

peey commented Aug 9, 2021

I'm not a contributor but was browsing the code related to another issue.

68ea786 (#1712) seems to fix exactly this issue. Could someone check if it's still present on the latest winston version? and if it's not then this may be closed.

@Faithfinder
Copy link
Contributor

Still the same on 3.3.3

@abarke
Copy link

abarke commented Nov 2, 2021

Using 3.3.3 we get the following...

const logger = winston.createLogger({
  level: "debug",
  defaultMeta: {
    meta: {
      client: { name, version }
    }
  },
  transports: [new winston.transports.Console()]
});

logger.log('error', 'Error message');
// {"level":"error","message":"Error message"}

logger.error('Error message');
// {"level":"error","message":"Error message","meta":{"client":{"name":"james-bond","version":"0.0.7"}}}

@gioamato
Copy link

gioamato commented Dec 20, 2021

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

So is this actually an issue or the expected behavior?

@maverick1872 maverick1872 added Metadata Applies to Metadata behavior Needs Investigation labels Feb 9, 2022
@maverick1872 maverick1872 self-assigned this Feb 9, 2022
@maverick1872
Copy link
Member

Possibly related to #2029

@maverick1872
Copy link
Member

Introduced the above example as a test case in #1989 and have verified this is functioning as we would expect. As such I will be closing this issue and letting the master issue track this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants