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

Formatter Concatenates Messages in logger.info('message1', {message: 'message2'}) #1634

Closed
1 of 2 tasks
mountHouli opened this issue Apr 12, 2019 · 2 comments
Closed
1 of 2 tasks

Comments

@mountHouli
Copy link

Please tell us about your environment:

What is the problem?

In the callback of the printf formatter below, in the info object, the value of info.message is my "log message" (see below) and "object message" (or "error message" as in the 2nd case) concatenated directly together (e.g. log messageobject message).

const winston = require('winston')
const { format, createLogger, transports } = winston

const formatter = format.printf(info => {
  return `The log message and the object message (or error message) are unfortuantely concatenated directly together without a space and/or colon+space in between: ${info.message}`
});

const logger = createLogger({
  level: 'debug',
  format: formatter,
  transports: [
    new transports.Console(),
  ],
})

// Case 1
logger.info('log message', { message: 'object message' });
// Case 2
logger.info('log message', new Error('error message'));

What do you expect to happen instead?

Depends on what the community thinks. Here are some options for the value of info.message:

  1. "log message: object message"
  2. "log message object message"
  3. "log message"

I like option 1, but I recognize this is a bit fancy and might catch users of this library by surprise.

Other information

I also tested and found this same type of issue occurring with the following formatters:
json,logstash, printf, prettyPrint, simple. I did not test any other formatters (I don't know if other formatters even exist).

Lastly, I recognize that this might be an issue not with winstonjs/winston but actually an issue with winstonjs/logform. If that is the case, I apologize. I took a brief look at the code today to figure out in which would be the correct repo to post this issue, but I could not make a determination. If someone says this is an issue with a different repo (e.g. winstonjs/logform) just LMK and I'll close this issue here and move it to the appropriate repo.

@mountHouli mountHouli changed the title Formatter Concatenates Messages in logger.info('message1', {message: 'message1'}) Formatter Concatenates Messages in logger.info('message1', {message: 'message2'}) Apr 12, 2019
@DABH
Copy link
Contributor

DABH commented Jun 22, 2020

Going to fix this via #1740 but if people would prefer another solution please do speak up. Thanks!

@DABH DABH closed this as completed Jun 22, 2020
@mountHouli
Copy link
Author

Thanks!

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

No branches or pull requests

2 participants