Skip to content

feat: log method support depth option#2087

Open
btea wants to merge 6 commits intohandlebars-lang:masterfrom
btea:feat/log-add-depth-option
Open

feat: log method support depth option#2087
btea wants to merge 6 commits intohandlebars-lang:masterfrom
btea:feat/log-add-depth-option

Conversation

@btea
Copy link
Copy Markdown

@btea btea commented Jul 22, 2025

Before creating a pull-request, please check https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md first.

Generally we like to see pull requests that

  • Please don't start pull requests for security issues. Instead, file a report at https://www.npmjs.com/advisories/report?package=handlebars
  • Maintain the existing code style
  • Are focused on a single change (i.e. avoid large refactoring or style adjustments in untouched code if not the primary goal of the pull request)
  • Have good commit messages
  • Have tests
  • Have the typings (types/index.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description.
  • Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
  • Currently, the 4.x-branch contains the latest version. Please target that branch in the PR.

In the nodejs environment, the default depth of objects printed by the console method is 2. Therefore, if you need to print out more levels of content in the object, you need to use the util.inspect method.

https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors

The log method currently supports level configuration. I would like to add a depth option so that more information can be clearly viewed when printing objects.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to add a depth option to Handlebars logging so that, in Node.js, logged objects can be printed with greater depth than the default console depth (2).

Changes:

  • Adds a depth property and parsing (convertDepth) to the core logger.
  • Extends the logger’s log implementation to apply Node.js util inspection with a configured depth.
  • Updates the built-in {{log}} helper to accept depth from hash/data and forward it to instance.log.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/handlebars/logger.js Introduces depth handling and Node-specific formatting logic inside the logger.
lib/handlebars/helpers/log.js Extends {{log}} helper to read depth from options and pass it through to logging.
Comments suppressed due to low confidence (1)

lib/handlebars/helpers/log.js:7

  • Initializing args as [undefined, undefined] means the helper will always call instance.log(level, undefined, ...), which breaks existing behavior/tests and any custom instance.log override expecting (level, ...message). Build the argument list without the extra placeholder and only insert a depth argument when it is actually provided.
  instance.registerHelper('log', function (/* message, options */) {
    let args = [undefined, undefined],
      options = arguments[arguments.length - 1];
    for (let i = 0; i < arguments.length - 1; i++) {
      args.push(arguments[i]);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/handlebars/logger.js
Comment thread lib/handlebars/logger.js Outdated
Comment thread lib/handlebars/logger.js
Comment thread lib/handlebars/logger.js Outdated
Comment thread lib/handlebars/helpers/log.js
btea and others added 2 commits March 31, 2026 21:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/handlebars/logger.js Outdated
Comment thread lib/handlebars/helpers/log.js Outdated
Comment thread lib/handlebars/helpers/log.js Outdated
Comment thread spec/builtins.js
btea and others added 2 commits March 31, 2026 22:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/handlebars/helpers/log.js Outdated
Comment thread lib/handlebars/logger.js Outdated
Comment thread lib/handlebars/logger.js
Comment thread spec/builtins.js Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants