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!")"Something normal is happening")
::Middleman::Logger.singleton.warn("This doesn't look right...")
::Middleman::Logger.singleton.debug("Won't be shown without `--verbose`")

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #middleman.

This post was filed under articles.

Related Posts

Other posts you may be interested in:

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.