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

[Bug]: defaultMeta returns object not string #2144

Open
renanyoy opened this issue Jun 3, 2022 · 10 comments
Open

[Bug]: defaultMeta returns object not string #2144

renanyoy opened this issue Jun 3, 2022 · 10 comments

Comments

@renanyoy
Copy link

renanyoy commented Jun 3, 2022

🔎 Search Terms

defaultmeta

The problem

defaultMeta does't appears as string in the log

const logger = winston.createLogger({
    level: 'info',
    format: production ? ecsFormat({ convertReqRes: true }) : winston.format.simple(),
    defaultMeta: { service: 'account' },
    transports: [new winston.transports.Console()]
});

but it displays service like that in the log

{
    "service":
    {
        "0": "a",
        "1": "c",
        "2": "c",
        "3": "o",
        "4": "u",
        "5": "n",
        "6": "t"
    }
}

What version of Winston presents the issue?

v3.3.3

What version of Node are you using?

v16.15.0

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

const logger = winston.createLogger({
    level: 'info',
    format: production ? ecsFormat({ convertReqRes: true }) : winston.format.simple(),
    defaultMeta: { service: 'account' },
    transports: [new winston.transports.Console()]
});

Additional information

No response

@wbt
Copy link
Contributor

wbt commented Jun 21, 2022

Out of curiosity, does this work in v3.7.0 and does it work in the latest version? Thanks to @maverick1872, 3.7.0 had a bunch of changes that might address this, but those changes were fairly quickly reverted due to an apparent bug.

@maverick1872
Copy link
Member

Whew. I've been out of the loop (life is a roller coaster) and haven't had time to come back around to this. I'm off Friday so I'll spend sometime fixing the underlying issue in #1989 in regards to Error Objects.

@renanyoy if you don't mind testing this in the latest version to confirm it's still present that would be appreciated!

@renanyoy
Copy link
Author

@maverick1872 I have upgraded to winston 3.7.2 and it's same

@wbt
Copy link
Contributor

wbt commented Jun 22, 2022

Seeing also if it works in 3.7.0 specifically helps figure out if that set of changes also addresses this problem.

@nTony46
Copy link

nTony46 commented Nov 8, 2022

Me and other students can work on this issue.

@wbt
Copy link
Contributor

wbt commented Nov 15, 2022

Thanks! Please first try to see if you can reproduce as described in the latest version, and then try 3.7.0 specifically, and report on whether that helps!

@nTony46
Copy link

nTony46 commented Nov 15, 2022

Yes, we were able to reproduce the issue on 3.8.2 and on 3.7.2 (couldn't npm install 3.7.0). I think that the issue @renanyoy had comes from the formatting when ‘production’ is true, which invokes the ecsFormat.

According to this ECS doc, the ‘service’ should be set as an object instead of a string, to something like defaultMeta: { service: {name:'account'}}.

A potential solution could just be reinitializing defaultMeta to defaultMeta: production ? {service: {name: 'account'}} : {service: 'account'}. We are thinking of making an input formatter so that both scenarios of declaring as a string or object would work and not cause the issue. Any thoughts?

@wbt
Copy link
Contributor

wbt commented Nov 15, 2022

What error did you encounter trying to install 3.7.0?
Also maybe try 3.7.1.

@nTony46
Copy link

nTony46 commented Nov 15, 2022

I ran npm install winston@3.7.0 and was met with:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for winston@3.7.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/codespace/.npm/_logs/2022-11-15T20_21_20_687Z-debug-0.log

Here is what was inside the log: https://pastebin.com/u8NNmjrb

I also ran npm install winston@3.7.1 which worked and I was able to reproduce the same issue.

@wbt
Copy link
Contributor

wbt commented Nov 15, 2022

Hmm, OK, thanks for the report. It's disappointing that 3.7.1 didn't solve it.

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

No branches or pull requests

4 participants