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

Add passthrough logging filter #2198

Closed
Snapstromegon opened this issue Feb 1, 2022 · 2 comments · Fixed by #2467
Closed

Add passthrough logging filter #2198

Snapstromegon opened this issue Feb 1, 2022 · 2 comments · Fixed by #2467

Comments

@Snapstromegon
Copy link
Member

Is your feature request related to a problem? Please describe.
When debugging especially filter chains in templates it's often easier if you can just drop a logging filter in between to see the result on the console.

Describe the solution you'd like
Maybe it would be useful to include such a feature like the default log filter (or even an adaption of it) in the default config, which returns the input value.

Describe alternatives you've considered
Option 1:
Store the filter chain before the logging in a variable and then use it once for logging and once for the actual work

Option 2:
I normally add such a filter myself:

eleventyConfig.addFilter("logging", (input, label, passthrough) => {
  console.log(`logging-${label}:`, input);
  if(passthrough) return input;
});

Additional context
This would help in cases where you have something like this in a template:

{{ someData | thatIsPassed | throughMultiple | filters | logging("Expected format?", true) | andStillUsed }}

I think switching the current log filter for the version above might not be compatible, because at the moment the direct binding to console.log allows passing any number of arguments, so it's either a breaking change, or needs to be a new filter.

@Snapstromegon
Copy link
Member Author

It just occured to me, that this is more or less possible in a compatible way by just always passing on the first argument since you can't pass more than one argument from the filter chain anyways and probably noone chained somethign after the current filter, since it always returns undefined right now.

Snapstromegon added a commit to Snapstromegon/eleventy that referenced this issue Jun 29, 2022
This change makes the `log` filter "passthrough" compatible, so you can put it in the middle of a filter chain.

Signed-off-by: Raphael Höser <raphael@hoeser.info>
zachleat added a commit that referenced this issue Jun 30, 2022
@zachleat zachleat added this to the Eleventy 2.0.0 milestone Jun 30, 2022
@zachleat
Copy link
Member

2.0.0-canary.13!

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

Successfully merging a pull request may close this issue.

2 participants