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

There is no meta in the format when message contains '%c' token. #1930

Open
1 of 2 tasks
Nikolay-Uvarov opened this issue Jun 8, 2021 · 1 comment
Open
1 of 2 tasks
Labels
Metadata Applies to Metadata behavior Needs Investigation

Comments

@Nikolay-Uvarov
Copy link

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • _node -v outputs: v14.17.0
  • Operating System? (Windows)
  • Language? (TypeScript)

What is the problem?

We intercept messages from the console. Some messages come with a '%c' character. When we pass an object to the logger method, only the message and level fields reach the format, the rest of the fields are undefined.
What we have in the file now:
2021-06-07 00:00:00.00+03:00 | 00000 | info | | %c next state color: #4CAF50; font-weight: bold [object Object] |

We are loosing meta here:

this.write(Object.assign({}, this.defaultMeta, {

What do you expect to happen instead?

We expect that the fields will be in our format and message won't be formatted.
What we expect in the file:
2021-06-07 00:00:00.000 +00:00 | 00000 | info | Renderer | %c next state color: #4CAF50; font-weight: bold [object Object] | (1) index.ts

Other information

Example of execution log method:
this.logger.log({ message, line, sourceId, scope }, undefined);

Logger has been created via:
WinstonModule.createLogger({ transports: [this.FileTransport] })

Example of format:
Line, sourceId and scope fields are undefined when message contains '%c'.
format.printf( ({ level, message = '', timestamp, line, sourceId, scope = '', exception = '' }) => `${String(timestamp)} | ${String(process.pid)} | ${String(level)} | ${String(scope)} | ${message} | ` + `${sourceId ? `(${String(line)}) ${String(sourceId)}` : ''}\n${String(exception)}`, );

Example of the message:
%c action color: #03A9F4; font-weight: bold [object Object]

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

Possibly related to #2029

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

No branches or pull requests

2 participants