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
Base64 encode binary data before logging #177
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,16 +36,18 @@ public function testCollect($query, $formatted) | |
public function getQueries() | ||
{ | ||
return array( | ||
// batchInsert | ||
array( | ||
'batch insert' => array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove these array keys? This isn't used by PHPUnit and is redundant given the inline comments above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The array keys are used by PHPUnit to name the data set being used. In debug output or when a test fails, instead of having "data set #1" failed, it'll put out "data set "batch insert" failed". However, if you don't want named datasets, I can remove the keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I had no idea. That sounds great, then 👍. If you like, we can drop the comments instead. |
||
array('db' => 'foo', 'collection' => 'bar', 'batchInsert' => true, 'num' => 1, 'data' => array('foo' => 'bar'), 'options' => array()), | ||
array('use foo;', 'db.bar.insert({ "foo": "bar" });'), | ||
), | ||
// find | ||
array( | ||
'find' => array( | ||
array('db' => 'foo', 'collection' => 'bar', 'find' => true, 'query' => array('foo' => null), 'fields' => array()), | ||
array('use foo;', 'db.bar.find({ "foo": null });'), | ||
), | ||
'bin data' => array( | ||
array('db' => 'foo', 'collection' => 'bar', 'update' => true, 'query' => array('_id' => 'foo'), 'newObj' => array('foo' => new \MongoBinData('junk data', \MongoBinData::BYTE_ARRAY))), | ||
arraY('use foo;', 'db.bar.update({ "_id": "foo" }, { "foo": new BinData(2, "' . base64_encode('junk data') . '") });'), | ||
) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also be logged using
BinData
format above? Otherwise, the base64 string will be indistinguishable from a regular string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree. I was trying to remain consistent as no other types are currently treated special in this logger. I'll change it to use the same format as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While changing this, I realized the output will end up looking a little strange since it will be wrapped in quotes since it's just being json_encoded.
It'll end up looking like
{"foo":{"bar":"new BinData(\"anVuayBkYXRh\", \"2\")"}}
.If that's fine, then I'll leave it as is. Otherwise, maybe just a tag like
"BINARY: anVuayBkYXRh, TYPE: 2"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, do other objects that get logged simply get casted to strings?
It's been some time since I saw the logger output for this bundle, so your example helped jog my memory.
I suppose the most preferable option would be to serialize the driver classes in the "strict JSON" format defined in: http://docs.mongodb.org/manual/reference/mongodb-extended-json/#data_binary (the
mongoexport
commands use that notation), but that would be outside the scope of this PR. Let's leave it as-is for now, then.