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

Logging a MongoDB ObjectID directly prints binary buffer #611

Closed
thomas-riccardi opened this issue Apr 22, 2015 · 8 comments
Closed

Logging a MongoDB ObjectID directly prints binary buffer #611

thomas-riccardi opened this issue Apr 22, 2015 · 8 comments

Comments

@thomas-riccardi
Copy link

var mongodb = require('mongodb');
var oid = new mongodb.ObjectID();

var winston = require('winston');

console.info(oid);
winston.info(oid);

Result:

553753a3e208f62631e6daa8
info:  _bsontype=ObjectID, id=U7S£ö&1æÚ¨

This is possibly related to #500, although it was not fixed by it.

@mattcasey
Copy link

you can always just use .toString().. would be great not to have to do that though

@indexzero
Copy link
Member

@triccardi-systran how would we detect if it is this type? Suggests a larger failure of our serialization of custom Objects which has been a problem even with natives (RegExp and Error).

@indexzero indexzero added the Bug label May 19, 2015
@thomas-riccardi
Copy link
Author

@indexzero I don't know how it could be fixed, maybe look at what other loggers do?
I confirm this is a larger issue: I already bug reported for RegExp, and I will again for mongodb 2.0 MongoError which pseudo-inherits native Error: only part of the object is logged (the stack, but not the message).

@thomas-riccardi
Copy link
Author

The MongoError has in fact been fixed in mongodb driver 2.0.28 by mongodb-js/mongodb-core/pull/14.

@kaetemi
Copy link

kaetemi commented Mar 26, 2016

This seems to be caused by cycle.decycle.

Modifying that function makes it work properly for me.

Added this line in there to do the magic if (value.toString && value.toString != Object.prototype.toString) { return value.toString(); }

@mostr
Copy link

mostr commented Jan 17, 2017

Is there any solution for this other than patching external lib as @kaetemi said (using latest release of winston)? I log MongoDB-stored object that has some ObjectID properties like this

logger.debug('Definition saved', definition)

and for these ObjectID props I get crap like _bsontype=ObjectID, 0=88, 1=54, 2=212, 3=140, 4=168, 5=147, 6=113, 7=163, 8=107, 9=62, 10=237, 11=253 out :(

I was trying to use rewriters/filters for that but with no luck (cannot reliably detect/rewrite these props)

@michaelfreund
Copy link

michaelfreund commented Feb 27, 2017

+1

using .toString() works but is extremely frustrating. any plans on fixing this?

currently doing stuff like JSON.parse(JSON.stringify(post)) 🙈

@indexzero
Copy link
Member

In winston@3.0.0 you can serialize exotic objects like this using custom formats. Please consider upgrading.

@indexzero indexzero removed the Bug label Mar 23, 2018
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

6 participants