Skip to content

If an object is passed as the first parameter it is not stringified #1606

@chdanielmueller

Description

@chdanielmueller

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v8.11.3
  • Operating System? macOS
  • Language? ES6/7

What is the problem?

If you just pass an object to a winston logger configured as the example it is being displayed as [Object object].
With a text in front and using the object as a second parameter it works.

Code:

import { createLogger, format, transports } from 'winston';

const logger = createLogger({
  transports: [
    new transports.Console({
      format: format.simple()
    })
  ]
});

const object = {
  some: 'property',
  another: 'property'
};
// Does not work
logger.info(object);
// Works
logger.info('Test', object);

Output

info: [object Object]
info: Test {"some":"property","another":"property"}

What do you expect to happen instead?

I expect the object to be converted to a string if I supply it as the first parameter.

Output

info: {"some":"property","another":"property"}
info: Test {"some":"property","another":"property"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions