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

Prettify Object Logs #69

Closed
wants to merge 4 commits into from
Closed

Conversation

sam-finch-tezos
Copy link
Contributor

@sam-finch-tezos sam-finch-tezos commented Oct 24, 2023

Context

The console is not currently spec compliant. Javascript objects are logged as [ object Object ] rather than displaying their properties. This PR updates that behaviour by printing the full object.

Description

  • Logging is updated to print objects longhand
  • Strings within logs are escaped to avoid multiline strings
  • The repl display is updated to print objects longhand
  • In the repl we explicitly check if a js value is callable and revert to the previous behaviour.

Manually testing the PR

In the repl

> console.log({ the_answer : 42}) // { the_answer: 42 }
> console.log({multiline: "Hello\nWorld"}) // { multiline: "Hello\nWorld" }
// it's still possible to fool it
> console.log(['"', {foo: 42}, '"', {foo: 42}], "😭") // [ """, {\n foo: 42\n}, """, { foo: 42 } ] 😭

Further work

  • Boa's display functions are still a wip. particularly for functions and string escapes. We could contribute to updating them.
  • Another idea for the future is to log the objects as tree-like value (e.g. XML/JSON etc), this could then be sent (via our logging infra) to the CLI and printed according the CLI's formatting of the tree.

Copy link
Collaborator

@johnyob johnyob left a comment

Choose a reason for hiding this comment

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

I'm getting some rather strange logs that seem to arise from escaped characters e.g. \n, spaces, etc. I'm fairly certain it occurs to due to the use of escape -- I'd prefer to keep the change to REPL but not the console until this escaping is fixed (e.g. by removing the \ns)

@johnyob
Copy link
Collaborator

johnyob commented Oct 24, 2023

One idea for the future is to log the objects as tree-like value (e.g. XML/JSON etc), this could then be sent (via our logging infra) to the CLI and printed according the CLI's formatting of the tree

@johnyob
Copy link
Collaborator

johnyob commented Oct 27, 2023

Closing in favour of the idea:

We want to stick with .display, we can enumerate lines before printing to the debug log, on each newline we insert the logging symbol + the associated indentation for the log group in the console API

@johnyob johnyob closed this Oct 27, 2023
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

Successfully merging this pull request may close these issues.

2 participants