FAQ
Hi Everybody,

I wonder if there is any simple way to always include runtime
information into Catalyst's logging.
In particular, I use Catalyst::Log::Log4perl to log activity of my
application, showing the user that triggered an event, such as:

$c->log->info("[".$c->user->username."] "."actual message");

and would like to avoid having to manually include the username in every
message.
Is it somehow possible to have Catalyst or Log4perl include the

"[".$c->user->username."]"

part automatically?

I already found (which I set in MyApp.pm)

Log::Log4perl::Layout::PatternLayout::add_global_cspec('U',
sub { return "xxx"; }
);

which adds a '%U' to the output pattern. However, I see no way to give
the closure the instance of the currently running MyApp (so I can assess
the user() method).

How do you handle situations like this?

Best regards,
Christian

Search Discussions

  • Onken at Jan 9, 2009 at 3:02 pm

    On Fri, 9 Jan 2009 15:00:28 +0100, Christian Lackas wrote:
    Hi Everybody,

    I wonder if there is any simple way to always include runtime
    information into Catalyst's logging.
    In particular, I use Catalyst::Log::Log4perl to log activity of my
    application, showing the user that triggered an event, such as:

    $c->log->info("[".$c->user->username."] "."actual message");

    and would like to avoid having to manually include the username in every
    message.
    Is it somehow possible to have Catalyst or Log4perl include the

    "[".$c->user->username."]"

    part automatically?
    Hi,

    in MyApp.pm:

    sub log_info {
    my $c = shift;
    $c->log->info("[".$c->user->username."] ". shift );
    }

    Now you can use $c->log_info("actual message") anywhere and the username
    gets prepended.

    moritz

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJan 9, '09 at 2:00p
activeJan 9, '09 at 3:02p
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Onken: 1 post Christian Lackas: 1 post

People

Translate

site design / logo © 2021 Grokbase