You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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';constlogger=createLogger({transports: [newtransports.Console({format: format.simple()})]});constobject={some: 'property',another: 'property'};// Does not worklogger.info(object);// Workslogger.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"}
The text was updated successfully, but these errors were encountered:
@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.
@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.
constobject={some: 'property',another: 'property'};console.info(object);// prints the object:// { some: 'property', another: 'property' }
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v8.11.3What 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:
Output
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
The text was updated successfully, but these errors were encountered: