-
Notifications
You must be signed in to change notification settings - Fork 59
Custom logs with frame object as the 2nd param #55 #56
Conversation
src/client.js
Outdated
@@ -45,8 +45,8 @@ class Client { | |||
// // append the debug log to a #debug div | |||
// $("#debug").append(str + "\n"); | |||
// }; | |||
debug(...args) { | |||
if (this.hasDebug) console.log(...args); | |||
debug(message, frame) { |
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.
If you are not going to use frame
inside the function, passing it as a parameter is redundant.
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.
true, I will remove the param
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.
Removing the param raises another question. The whole PR ends up moving let frame = new Frame(command, headers, body);
from marshall
to _tramsit
with no obvious gain as frame
will not be used as a second param to debug
function. The PR looks kinda pointless. I wonder if there is something else I don't see.
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.
Yes, there is when overriding the client.debug
then you have access to command
, headers
and body
separately and can log what you need. We are for example truncation Authorization
header:
client.debug = (text, frame) => {
if (frame.headers && frame.headers.Authorization) {
const newHeaders = evolve({
Authorization: truncate
}, frame.headers)
log.debug(_frameToString(frame.command, newHeaders, frame.body))
}
}
It's really much easier to read the logs now as our JWT was ocupying 3 console lines. We may soon strip some content of the body
or completely remove some headers.
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.
And why is the current signature not suiting you? I mean from what I know (text, frame)
complies with (...args)
. Declaring
client.debug = (...args) => {
if (args[1].headers && args[1].headers.Authorization) {
const newHeaders = evolve({
Authorization: truncate
}, args[1].headers)
log.debug(_frameToString(args[1].command, newHeaders, args[1].body))
}
}
and calling debug(text, frame)
should work the same.
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 am using ES6 but it can be rewritten to vanilla very easily. Maybe the ramda library is confusing you?
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'm just asking cause I realized that we are not providing typescript types
for the debug
function and this will definitely cause problems for those who want to override the function.
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've never used Typescript but it's another obstacle. What do you say about using the other function debugWithFrame(frame, ...args)
. I definitely think it's necessary for us to have a finer way to pick what we would include in our logs than parsing a 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'm not familiar with Ramda
(man there are so many libraries out there), but I stick to Zakas
quote that named arguments in ECMAScript are a convenience and not a necessity
.
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.
@JimiC check it out again. I've removed the unused param |
@zatziky please do not push dist files. Only src. |
@JimiC I know this but I didn't realize what you want me to see. |
closed in favour of #58 |
This is a proposal for #55
@JSteunou