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 metalsmith.debug/log method #259
Comments
Metalsmith and many plugins use debug. Run your build with It would be good to have a plugins best practices document. |
THIS. 👍 Encourages best practices while not restricting freedom or experimentation. |
(It’s been a while! :) Good to see Metalsmith dev is alive and well.)
TL;DRQ: I checked out ReasoningPersonally, I love npmlog because it has good defaults, but allows you to really fine-tune it if you want: prefixes, optional heading, colors, pause/resume and flush messages that accumulated while paused, and common-sense log levels (that can be further fine-tuned if needed). EDIT: Forgot I said this in my original post!
There is a long debate about whether the Failing that, maybe we could stick to Node.js’s builtin (Regardless of the debugger, a good “Best Practices” doc for plugin authors is still a solid good idea.) |
@zerin debug sure does have it's limitations. I get what you're saying re: "more complex than originally intended", but that same thread does have significant support for improvements. I think one of the big problems you would face in trying to change to a new defacto standard, is that you'd never really be able to leave debug behind. Suppose we wrote a best practice doc saying "use npmlog", loads of maintainers just wouldn't even be aware of the community change. Even when PRs are submitted many maintainers just aren't interested in reviewing & patching. Usually I'm the last person to say "just keep doing what we're doing because it will suck to change", but in this case the sedentary nature of the plugin ecosystem will be a big problem to overcome. Re: the possible improvements linked above, they notably include a middleware layer. I don't really understand how they intend to implement, but based on @thebigredgeek 's example, you might be able to, say, add middleware to redirect all debug output to npmlog. Re: your original post about lots of plugins, difficult to track down.. I published metalsmith-debug-ui the other day which aims to alleviate this exact problem. Basically lets you step through the build process and presents the files & metadata structures in a nice navigable browser based ui after each plugin. It's new, needs some improvements, but generally works and is super effective! As an aside, debug-ui struggles with the same problem of trying to re-route debug output to the browser, until debug v3 is released debug-ui will require explicit support from plugins, which seems unlikely. |
We are very much open to expanding |
Having thought through this a little more, and reviewed the debug v3 discussion issue, it might be a good idea to have metalsmith core provide access to debug. The problem with using debug in the decentralised way it's used in metalsmith is that there's no point from which you can effect all debug instances. For example, suppose you want to build with a cron job and store debug output, or in the case of metalsmith-debug-ui you want to listen to all debug output and display it in the browser as well as the console output. Currently debug allows you to switch out
This doesn't really work with metalsmith plugin style structure because whilst changing Looking through the debug v3 discussion thread, I don't think that v3 is intended to resolve this difficulty. The middleware deal would merely allow more complex augmentations of One way to solve this would be for metalsmith core to expose access to debug through it's api, something like
then if you masked I get that metalsmith core is very resistant to including this kind of kitchen sink functionality, but I'll point out that this particular improvement is firstly, not possible to implement with a plugin (plugins can't mutate the metalsmith instance), and secondly concerns abstracting the metalsmith build environment rather than offering some kind of plugin type functionality. As an aside, not having this kind of functionality hasn't really cost us much in the past, however the debug v3 improvements like middleware would be unusable by metalsmith & plugins. |
Most core plugins now have an explicit Debug section in the readme. As the logging guidelines issue is at my top-of-mind, I'm repurposing this issue as a feature request for a Another option would be to define it as The only remaining question I am split on is whether to call the method |
Summary
It would be awesome if there were some sort of convention for plugins and logging. Perhaps we could draft up a recommendation?
I’m just imagining something that users could pass to the plugin’s configuration as an option, or some such. It would still be up to the plugin authors to use it responsibly.
Rationale
One of Metalsmith’s strengths is its hands-off approach to plugins. This promotes experimentation, which IMO is a good thing.
It also promotes using lots of plugins. This is IMO also a good thing…until something goes wrong.
This leads to errors that become harder and harder to track down as the number of plugins increases.
newlyAddedPlugin
? Or didnewlyAddedPlugin
work “correctly” but cause something to break further down the pipeline?A set of logging conventions would provide a little unity in terms of user-friendliness, while still preserving the ultimate freedoms that Metalsmith plugins enjoy.
The text was updated successfully, but these errors were encountered: