SW Designs

Technology and Photography

Behat Monolog Extension

Good application logging is invaluable. If offers insight into what your application is doing under normal conditions as well as somewhere to log information about errors. Combined with tools such as Graphite or Splunk, you can create real-time dashboards showing how your application is performing. Not only does this aid developers, but also operational teams to indentify abnormal patterns quickly.

These benefits also apply to automated test suites. They start off small and easy to understand. As they grow, testing more components and requiring more fixtures, they can become difficult to understand. Take an online shop for example, fixturing and testing the product catalogue is probably significantly more straightforward compared to completing a purchase.

To help those creating Behat test suties, I’ve create a Monolog extension for it. It works by injecting a log channel into each Behat Context, including Sub-Contexts. The name of the logger object is configurable, as are the handlers, although only the Stream hanlder (for writing to files) is supported for now. To get you up ‘n running quickly, there’s also an example project demostrating howto use it.

Below is the output when the stream hanlder is figured to write to php://stdout,

Any feedback, comments or suggestions are welcome.

Comments