Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Custom logs with frame object as the 2nd param #55 #56

Closed
wants to merge 4 commits into from

Conversation

zatziky
Copy link

@zatziky zatziky commented Sep 30, 2017

This is a proposal for #55

@JSteunou

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) {
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

@JimiC JimiC Oct 2, 2017

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.

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, why not. I'll wait with further changes until we agree on them. @JSteunou @JimiC

@zatziky
Copy link
Author

zatziky commented Oct 2, 2017

@JimiC check it out again. I've removed the unused param frame

@JSteunou
Copy link
Owner

JSteunou commented Oct 2, 2017

@zatziky please do not push dist files. Only src.

@JimiC
Copy link
Contributor

JimiC commented Oct 2, 2017

According to Professional JavaScript for web developers by Nicholas C. Zakas


c613a1a696fd7e8a0354450611949c4a98b337130b539922d2 pimgpsh_mobile_save_distr

658cf8a2a0edec822d472502ac60fb761f5e81b4d53ae4d881 pimgpsh_mobile_save_distr

adcf2d2383a44d5707b56b74912667ae296e78123f11ae2734 pimgpsh_mobile_save_distr

12242453de3ce1b38e242a74bc31f6a918308c187d64a1eab0 pimgpsh_mobile_save_distr

@zatziky
Copy link
Author

zatziky commented Oct 2, 2017

@JimiC I know this but I didn't realize what you want me to see.

@JimiC JimiC mentioned this pull request Oct 2, 2017
@JSteunou
Copy link
Owner

JSteunou commented Oct 9, 2017

closed in favour of #58

@JSteunou JSteunou closed this Oct 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants