Debugging Middleman Code With Middleman's Logger
I've recently been working with the Middleman static site generator, which I'm finding a nice experience because it's written in Ruby.
I've been enjoying the fact that you can write your own helper methods that can perform custom processing as part of outputting things in the page.
Because some of this can be somewhat complex processing, we would likely want to add test coverage of the functionality through unit tests.
However, if the helpers you're writing are heavily dependent on the data in the site, and the page you're trying to render, it can be a little cumbersome to replicate it correctly for a unit test ahead of time, so you may need to add some debug logging.
To do this, I'd hoped to use the very basic approach of printing to stdout using
puts, which I found works pretty nicely.
Another way we can do this, is to use Middleman's underlying logging infrastructure, and call the logger, via its singleton:
::Middleman::Logger.singleton.error("Call someone out of bed - we've got a problem!") ::Middleman::Logger.singleton.info("Something normal is happening") ::Middleman::Logger.singleton.warn("This doesn't look right...") ::Middleman::Logger.singleton.debug("Won't be shown without `--verbose`")