February 23, 2011

Logginz ur console with Mojolicious

Update Plugin has been updated with more functionality. See latest blog post.

A new Mojolicious plugin has been released, Mojolicious::Plugin::ConsoleLogger.

By default, Mojolicious will send debug messages to a log/[mode].log file; if the log directory does not exist, messages will default to the terminal console.

You can use any of the four logging groups for customized messages:

With Mojolicious::Plugin::ConsoleLogger, you can log these same messages directly to your browser console.

Declare the plugin:

And view all your log messages directly from your browser:

console logger devtools screenshot.png

That's all well and good, but let's take it a step further. You can even see error messages when the template is missing:

template not found browser console error.png

Or when there's a template error:

syntax error template mojo console logger.png

Even when there's a Perl compilation error:

perl error mojo console logger.png

As always, Mojolicious installs in about a minute:

curl -L cpanmin.us | perl - Mojolicious::Plugin::ConsoleLogger

Disclaimer: Implementation stolen from Plack::Middleware::ConsoleLogger

comments powered by Disqus