[Catalyst] Best Practices : Logging

J. Shirley jshirley at gmail.com
Mon Nov 16 22:59:43 GMT 2009


On Mon, Nov 16, 2009 at 2:47 PM, Jon <jonfdaily at wetxt.com> wrote:

> Hello,
> I'm building a new Catalyst app, and am trying to follow the best
> practices.  What do people typically do for logging in their Model
> classes?
>
> I would like to have something like,
>
> package App::Model::SomeModel;
> use strict;
> use warnings;
> use parent 'Catalyst::Model::Adaptor';
>
> __PACKAGE__->config(
>    class =3D> 'App::Logic::SomeModel',
> );
>
>
> package App::SomeModel;
> use Moose;
>
> has 'log' =3D> (is =3D> 'ro', isa =3D> 'Catalyst::Plugin::Log::Handler',
> lazy_build =3D> 1);
>
> ....
>
> sub _build_log {
>   my ($self) =3D @_;
>   $self->log(Catalyst::Plugin::Log::Handler->new());
> }
>
>
> But I don't want to have to manually pass configuration details to it
> each time.  There is probably a more standard way to take care of this
> that I'm just not aware of.  Can I set it up automatically in my
> adaptor class?
>
> Thanks,
> - Jon
>
>
>
I typically use a pattern similar to what is found in InstancePerContext,
and just do $instance->log( $c->log ) (or, in instantiation on the
build_per_context_instance)

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091116/1fd88=
fe1/attachment.htm


More information about the Catalyst mailing list