Introducing DBIx::Class::UnicornLogger

More than a 1.5 years ago we added color coded, formatted SQL output to DBIx::Class. Since then I’ve tried adding various configurable logging facilities to the core, but I haven’t had much luck getting the API for that whipped into shape. So I’m giving up on getting it into the core for now and releasing it separately. It’s pretty rough around the edges, but it’s a logger, so it’s not like you could depend on it working a certain way and get into any kind of trouble with it (yet.)

Meet DBIx::Class::UnicornLogger

(Every time someone gets upset about a module called Dad I name a module named something actually ridiculous.) First off, here’s some of the output (after color has been stripped)

[2012-05-18 23:06:43]\[/home/frew/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/DBIx/Class/Storage/DBI.pm:1489]
 ** SELECT "me"."id", "me"."kind_of_id", "me"."materialized_path", "me"."name", "me"."description"
 --   FROM "ingredients" "me"
 --   LIMIT '3'

The above was generated by the following configuration:

my $pp = DBIx::Class::UnicornLogger->new({
   tree => { profile => 'console' },
   profile => 'console',
   format => '[%d]\[%F:%L]%n ** %m',
   multiline_format => ' -- %m',
});

First off, clearly I need to set up a good default “clan.” The code supports it, but for some reason I never got around to making a good default. Next, there’s a bug somewhere that makes the location logging (specifically the subroutine part) not work. That’s a hassle and desperately needs to be fixed. Anyway, the idea is to make a neat logger that gives more information than the default trace tool. Eventually I plan on including total time for SQL to execute as well.

If you’re interested in trying this out yourself put the following snippet in your schema:

use DBIx::Class::UnicornLogger;
my $pp = DBIx::Class::UnicornLogger->new({
   tree => { profile => 'console' },
   profile => 'console',
   format => '[%d]\[%F:%L]%n ** %m',
   multiline_format => ' -- %m',
});

sub connection {
   my $self = shift;

   my $ret = $self->next::method(@_);

   $self->storage->debugobj($pp);

   $ret
};

So please, try it out, send me patches and ideas, and we can realize our hopes and dreams of unicorn logging!

Posted Fri, May 25, 2012

If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.