feat: log method support depth option#2087
feat: log method support depth option#2087btea wants to merge 6 commits intohandlebars-lang:masterfrom
Conversation
There was a problem hiding this comment.
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
depthproperty and parsing (convertDepth) to the core logger. - Extends the logger’s
logimplementation to apply Node.jsutilinspection with a configured depth. - Updates the built-in
{{log}}helper to acceptdepthfrom hash/data and forward it toinstance.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
argsas[undefined, undefined]means the helper will always callinstance.log(level, undefined, ...), which breaks existing behavior/tests and any custominstance.logoverride expecting(level, ...message). Build the argument list without the extra placeholder and only insert adepthargument 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
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.inspectmethod.https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors
The
logmethod currently supportslevelconfiguration. I would like to add adepthoption so that more information can be clearly viewed when printing objects.