Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Best Practices : Logging

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


jonfdaily at wetxt

Nov 16, 2009, 2:47 PM

Post #1 of 2 (653 views)
Permalink
Best Practices : Logging

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 => 'App::Logic::SomeModel',
);


package App::SomeModel;
use Moose;

has 'log' => (is => 'ro', isa => 'Catalyst::Plugin::Log::Handler',
lazy_build => 1);

....

sub _build_log {
my ($self) = @_;
$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

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


jshirley at gmail

Nov 16, 2009, 2:59 PM

Post #2 of 2 (591 views)
Permalink
Re: Best Practices : Logging [In reply to]

On Mon, Nov 16, 2009 at 2:47 PM, Jon <jonfdaily [at] wetxt> 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 => 'App::Logic::SomeModel',
> );
>
>
> package App::SomeModel;
> use Moose;
>
> has 'log' => (is => 'ro', isa => 'Catalyst::Plugin::Log::Handler',
> lazy_build => 1);
>
> ....
>
> sub _build_log {
> my ($self) = @_;
> $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

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.