[Catalyst] best practice for a protocol mechanism?

J. Shirley jshirley at gmail.com
Thu Sep 10 13:24:08 GMT 2009


On Thu, Sep 10, 2009 at 6:43 AM, Jens Schwarz <blacky6767 at gmx.de> wrote:

> Oh, *err* right. I meant 'logging' and not 'protocol' *douh*.
>
> Well, right now I have a proto^Wlogging action in my Root controller that=
 I
> call everytime I want something to be logged in my DB.
> P.ex.:
>
> package MyApp::Controller::Book;
> (...)
> sub create ... {
> ...
> $c->forward("MyApp::Controller::Root","myLoggingAction",["some message th=
at
> should be logged"]);
> }
>
> In addition to this, I have a logging controller, that simply displays the
> list of logged messages from the DB.
>
> Think of something like:
>
> | Timestamp        | User   | Action           |
> +------------------+--------+------------------+
> | 2009-09-10 10:30 | foobar | created new book |
>
> So the question is: Is there a neater way of doing this? Some kind of best
> practice?
>
>
Hi Jens,

I would do one of two things.

The first is to build a custom Catalyst::Log class if that is what you are
looking for, or you could even just use Catalyst::Log::Log4perl and
configure it as necessary. (Using Catalyst::Log::Log4perl is what I would
use).

Then, simply use $c->log->whatever.

The other option is to create a model for this, and change the code to:

$c->model('Logger')->log("Message");

If you use the model approach, you can use
Catalyst::Component::ACCEPT_CONTEXT to access $c->model('Schema') and
$c->user.

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090910/4a180=
ac7/attachment.htm


More information about the Catalyst mailing list