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

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

Open
1 of 2 tasks
chdanielmueller opened this issue Feb 26, 2019 · 3 comments
Open
1 of 2 tasks

Comments

@chdanielmueller
Copy link

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"}
@DABH
Copy link
Contributor

DABH commented Mar 24, 2019

winstonjs/logform#88

@nagapavan
Copy link

@chdanielmueller I feel like printing [object Object] is an acceptable, as the protocol is to have first argument as string and second as object. Type Checking first argument every time to confirm if it's an Object/Array/String will be a costly operation for a framework.

Usually in Java logger.info(object) translates to JSON version of Object, only if we implement toString() method, so what you are expecting might be fair in that context.

@adnanalawiyat
Copy link

adnanalawiyat commented Aug 1, 2019

@chdanielmueller I feel like printing [object Object] is an acceptable, as the protocol is to have first argument as string and second as object. Type Checking first argument every time to confirm if it's an Object/Array/String will be a costly operation for a framework.

Usually in Java logger.info(object) translates to JSON version of Object, only if we implement toString() method, so what you are expecting might be fair in that context.

what protocol is that ? I'm not seeing anywhere in the docs that first argument should be a string.

const object = {
  some: 'property',
  another: 'property'
};

console.info(object);
// prints the object:
//  { some: 'property', another: 'property' }

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

4 participants