Re: [Catalyst] Trapping added errors with the correct caller

2012-10-16 Thread Alexander Hartmaier
On 2012-10-15 18:55, Robert Rothenberg wrote:
> On 15/10/12 17:49 Alexander Hartmaier wrote:
>> On 2012-10-15 18:03, Robert Rothenberg wrote:
>>> On 15/10/12 15:21 Alexander Hartmaier wrote:
 I recommend to use a logging module like Log::Log4perl::Catalyst and do
 all your app logging there.
>>> I use Log::Dispatch. (The application is already deployed, and it's not
>>> feasible to change it to Log4perl now.)
>> If you're already using a logger but the default Catalyst one that's fine.
>>> I don't see where in your code you trap calls to $c->error() and log them.
>> All log messages are going to your logger object, Log::Dispatch in your
>> case, not just errors.
>> Just configure Log::Dispatch to do with them what you want it to do (log
>> to a separate file, mail them, etc. ).
> You don't seem to understand my original question.
>
> The "end" method of the Root controller looks for errors in $c->error() and
> logs them, then displays a custom error page.  The problem with doing that
> is that it does not say where the error occurred.  So I want to modify
> $c->error() to log it every time something is added, which is actually quite
> easy.  But I want to use something like Sub::Uplevel so that the logger does
> not say the wrapper module triggered the error.
You mean *your* end action code? You haven't showed it and my crystal
ball is broken.

Does it make a difference for you if the error is logged when it
occurred instead of the end of the request?
My apps normally die on the first error which gets logged. The die error
message includes the filename and line number which is sufficient for me.


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

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


Re: [Catalyst] Trapping added errors with the correct caller

2012-10-16 Thread Alexander Hartmaier
On 2012-10-16 00:04, Kieren Diment wrote:
> I've had a lot of luck with Log::Contextual recently.  It's nice for easily 
> getting logging into model classes.
I'm going to use Log::Any for that in the future.
>
> On 16/10/2012, at 1:21 AM, Alexander Hartmaier wrote:
>
>> I recommend to use a logging module like Log::Log4perl::Catalyst and do
>> all your app logging there.
>>
>> My log package for NAC::Web:NAC looks like this:
>>
>> package NAC::Web::NAC::Log;
>> use Moose;
>> use Catalyst::Log;
>> use namespace::autoclean;
>>
>> BEGIN { extends 'Log::Log4perl::Catalyst'; }
>>
>> =head1 NAME
>>
>> NAC::Web::NAC::Log - Logger for NAC::Web::NAC
>>
>> =cut
>>
>> # import _dump method from Catalyst::Log
>> *_dump = \&Catalyst::Log::_dump;
>>
>> 1;
>>
>> My app uses it with:
>>
>> =item finalize_config
>>
>> Initializes the logger after the config file merging and loading is done.
>>
>> =cut
>>
>> sub finalize_config {
>>my $class = shift;
>>$class->next::method(@_);
>>$class->log(NAC::Web::NAC::Log->new($class->config->{log}));
>> }
>>
>> # Start the application
>> __PACKAGE__->setup();
>>
>> around 'prepare' => sub {
>>my $orig = shift;
>>my $self = shift;
>>
>>Log::Log4perl::MDC->remove();
>>
>>my $c = $self->$orig(@_);
>>
>>Log::Log4perl::MDC->put( "username", $c->user->username )
>>if $c->user_exists;
>>
>>return $c;
>> };
>>
>> And this is how the app's prod config file looks like:
>>
>> 
>>log4perl.logger "WARN, FILE, MAIL"
>>log4perl.appender.FILE
>> "Log::Log4perl::Appender::File"
>>log4perl.appender.FILE.filename
>> "/home/nac/log/nac-web-nac.log"
>>log4perl.appender.FILE.utf8 1
>>log4perl.appender.FILE.syswrite 1
>>log4perl.appender.FILE.layout
>> "Log::Log4perl::Layout::PatternLayout"
>>log4perl.appender.FILE.layout.ConversionPattern "%d{-MM-dd
>> HH:mm:ss} %-5p %X{username} %m%n"
>>log4perl.appender.MAIL
>> "Log::Dispatch::Email::MailSend"
>>log4perl.appender.MAIL.ThresholdERROR
>>log4perl.appender.MAIL.from "n...@domain.com"
>>log4perl.appender.MAIL.to
>> "app-err...@domain.com"
>>log4perl.appender.MAIL.subject  "[NAC::Web::NAC]
>> errors"
>>log4perl.appender.MAIL.buffered 0
>>log4perl.appender.MAIL.layout   "PatternLayout"
>>log4perl.appender.MAIL.layout.ConversionPattern "%d{-MM-dd
>> HH:mm:ss} %-5p %X{username} %m%n"
>> 
>>
>> Best regards, Alex (abraxxa)
>>
>> On 2012-10-11 14:38, Robert Rothenberg wrote:
>>> I would like to trap every error added to $c->error() and log it, noting the
>>> caller (filename, line number) in the logs.
>>>
>>> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
>>> plugin that overrides $c->error with the following method:
>>>
>>>  use MRO::Compat;
>>>  use namespace::autoclean;
>>>
>>>  sub error {
>>>my ($c, @args) = @_;
>>>
>>>foreach my $arg (@args) {
>>>if ($arg) {
>>>
>>>$c->log->error($arg);
>>>}
>>>}
>>>
>>>return $c->next::method(@args);
>>> }
>>>
>>> But this only logs errors as coming from my plugin.
>>>
>>> Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
>>> $Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.
>>>
>>> I also tried writing the plugin as a Moose::Role that adds my trap before
>>> error, but then it claims to be from one of the internal Moose classes in my
>>> logs.
>>>
>>> I can manually get the caller using caller(0) and add them to the log
>>> messages, but that's a bit clumsy (and overrides log formats that don't
>>> include the information).
>>>
>>> So... what is the best practice for trapping errors in a way that preserves
>>> caller information?
>>>
>>>
>>> ___
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/
>>
>>
>> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
>> Handelsgericht Wien, FN 79340b
>> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>> Notice: This e-mail contains information that is confidential and may be 
>> privileged.
>> If you are not the intended recipient, please notify the sender and then
>> delete this e-mail immediately.
>> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>>
>> ___
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.

Re: [Catalyst] Trapping added errors with the correct caller

2012-10-15 Thread Kieren Diment
I've had a lot of luck with Log::Contextual recently.  It's nice for easily 
getting logging into model classes.

On 16/10/2012, at 1:21 AM, Alexander Hartmaier wrote:

> I recommend to use a logging module like Log::Log4perl::Catalyst and do
> all your app logging there.
> 
> My log package for NAC::Web:NAC looks like this:
> 
> package NAC::Web::NAC::Log;
> use Moose;
> use Catalyst::Log;
> use namespace::autoclean;
> 
> BEGIN { extends 'Log::Log4perl::Catalyst'; }
> 
> =head1 NAME
> 
> NAC::Web::NAC::Log - Logger for NAC::Web::NAC
> 
> =cut
> 
> # import _dump method from Catalyst::Log
> *_dump = \&Catalyst::Log::_dump;
> 
> 1;
> 
> My app uses it with:
> 
> =item finalize_config
> 
> Initializes the logger after the config file merging and loading is done.
> 
> =cut
> 
> sub finalize_config {
>my $class = shift;
>$class->next::method(@_);
>$class->log(NAC::Web::NAC::Log->new($class->config->{log}));
> }
> 
> # Start the application
> __PACKAGE__->setup();
> 
> around 'prepare' => sub {
>my $orig = shift;
>my $self = shift;
> 
>Log::Log4perl::MDC->remove();
> 
>my $c = $self->$orig(@_);
> 
>Log::Log4perl::MDC->put( "username", $c->user->username )
>if $c->user_exists;
> 
>return $c;
> };
> 
> And this is how the app's prod config file looks like:
> 
> 
>log4perl.logger "WARN, FILE, MAIL"
>log4perl.appender.FILE
> "Log::Log4perl::Appender::File"
>log4perl.appender.FILE.filename
> "/home/nac/log/nac-web-nac.log"
>log4perl.appender.FILE.utf8 1
>log4perl.appender.FILE.syswrite 1
>log4perl.appender.FILE.layout
> "Log::Log4perl::Layout::PatternLayout"
>log4perl.appender.FILE.layout.ConversionPattern "%d{-MM-dd
> HH:mm:ss} %-5p %X{username} %m%n"
>log4perl.appender.MAIL
> "Log::Dispatch::Email::MailSend"
>log4perl.appender.MAIL.ThresholdERROR
>log4perl.appender.MAIL.from "n...@domain.com"
>log4perl.appender.MAIL.to
> "app-err...@domain.com"
>log4perl.appender.MAIL.subject  "[NAC::Web::NAC]
> errors"
>log4perl.appender.MAIL.buffered 0
>log4perl.appender.MAIL.layout   "PatternLayout"
>log4perl.appender.MAIL.layout.ConversionPattern "%d{-MM-dd
> HH:mm:ss} %-5p %X{username} %m%n"
> 
> 
> Best regards, Alex (abraxxa)
> 
> On 2012-10-11 14:38, Robert Rothenberg wrote:
>> I would like to trap every error added to $c->error() and log it, noting the
>> caller (filename, line number) in the logs.
>> 
>> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
>> plugin that overrides $c->error with the following method:
>> 
>>  use MRO::Compat;
>>  use namespace::autoclean;
>> 
>>  sub error {
>>my ($c, @args) = @_;
>> 
>>foreach my $arg (@args) {
>>if ($arg) {
>> 
>>$c->log->error($arg);
>>}
>>}
>> 
>>return $c->next::method(@args);
>> }
>> 
>> But this only logs errors as coming from my plugin.
>> 
>> Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
>> $Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.
>> 
>> I also tried writing the plugin as a Moose::Role that adds my trap before
>> error, but then it claims to be from one of the internal Moose classes in my
>> logs.
>> 
>> I can manually get the caller using caller(0) and add them to the log
>> messages, but that's a bit clumsy (and overrides log formats that don't
>> include the information).
>> 
>> So... what is the best practice for trapping errors in a way that preserves
>> caller information?
>> 
>> 
>> ___
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
> 
> 
> 
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> Handelsgericht Wien, FN 79340b
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> Notice: This e-mail contains information that is confidential and may be 
> privileged.
> If you are not the intended recipient, please notify the sender and then
> delete this e-mail immediately.
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> 
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com

Re: [Catalyst] Trapping added errors with the correct caller

2012-10-15 Thread Robert Rothenberg
On 15/10/12 17:49 Alexander Hartmaier wrote:
> On 2012-10-15 18:03, Robert Rothenberg wrote:
>> On 15/10/12 15:21 Alexander Hartmaier wrote:
>>> I recommend to use a logging module like Log::Log4perl::Catalyst and do
>>> all your app logging there.
>> I use Log::Dispatch. (The application is already deployed, and it's not
>> feasible to change it to Log4perl now.)
> If you're already using a logger but the default Catalyst one that's fine.
>>
>> I don't see where in your code you trap calls to $c->error() and log them.
> All log messages are going to your logger object, Log::Dispatch in your
> case, not just errors.
> Just configure Log::Dispatch to do with them what you want it to do (log
> to a separate file, mail them, etc. ).

You don't seem to understand my original question.

The "end" method of the Root controller looks for errors in $c->error() and
logs them, then displays a custom error page.  The problem with doing that
is that it does not say where the error occurred.  So I want to modify
$c->error() to log it every time something is added, which is actually quite
easy.  But I want to use something like Sub::Uplevel so that the logger does
not say the wrapper module triggered the error.


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


Re: [Catalyst] Trapping added errors with the correct caller

2012-10-15 Thread Alexander Hartmaier
On 2012-10-15 18:03, Robert Rothenberg wrote:
> On 15/10/12 15:21 Alexander Hartmaier wrote:
>> I recommend to use a logging module like Log::Log4perl::Catalyst and do
>> all your app logging there.
> I use Log::Dispatch. (The application is already deployed, and it's not
> feasible to change it to Log4perl now.)
If you're already using a logger but the default Catalyst one that's fine.
>
> I don't see where in your code you trap calls to $c->error() and log them.
All log messages are going to your logger object, Log::Dispatch in your
case, not just errors.
Just configure Log::Dispatch to do with them what you want it to do (log
to a separate file, mail them, etc. ).
>
>> My log package for NAC::Web:NAC looks like this:
>>
>> package NAC::Web::NAC::Log;
>> use Moose;
>> use Catalyst::Log;
>> use namespace::autoclean;
>>
>> BEGIN { extends 'Log::Log4perl::Catalyst'; }
>>
>> =head1 NAME
>>
>> NAC::Web::NAC::Log - Logger for NAC::Web::NAC
>>
>> =cut
>>
>> # import _dump method from Catalyst::Log
>> *_dump = \&Catalyst::Log::_dump;
>>
>> 1;
>>
>> My app uses it with:
>>
>> =item finalize_config
>>
>> Initializes the logger after the config file merging and loading is done.
>>
>> =cut
>>
>> sub finalize_config {
>> my $class = shift;
>> $class->next::method(@_);
>> $class->log(NAC::Web::NAC::Log->new($class->config->{log}));
>> }
>>
>> # Start the application
>> __PACKAGE__->setup();
>>
>> around 'prepare' => sub {
>> my $orig = shift;
>> my $self = shift;
>>
>> Log::Log4perl::MDC->remove();
>>
>> my $c = $self->$orig(@_);
>>
>> Log::Log4perl::MDC->put( "username", $c->user->username )
>> if $c->user_exists;
>>
>> return $c;
>> };
>>
>> And this is how the app's prod config file looks like:
>>
>> 
>> log4perl.logger "WARN, FILE, MAIL"
>> log4perl.appender.FILE
>> "Log::Log4perl::Appender::File"
>> log4perl.appender.FILE.filename
>> "/home/nac/log/nac-web-nac.log"
>> log4perl.appender.FILE.utf8 1
>> log4perl.appender.FILE.syswrite 1
>> log4perl.appender.FILE.layout
>> "Log::Log4perl::Layout::PatternLayout"
>> log4perl.appender.FILE.layout.ConversionPattern "%d{-MM-dd
>> HH:mm:ss} %-5p %X{username} %m%n"
>> log4perl.appender.MAIL
>> "Log::Dispatch::Email::MailSend"
>> log4perl.appender.MAIL.ThresholdERROR
>> log4perl.appender.MAIL.from "n...@domain.com"
>> log4perl.appender.MAIL.to
>> "app-err...@domain.com"
>> log4perl.appender.MAIL.subject  "[NAC::Web::NAC]
>> errors"
>> log4perl.appender.MAIL.buffered 0
>> log4perl.appender.MAIL.layout   "PatternLayout"
>> log4perl.appender.MAIL.layout.ConversionPattern "%d{-MM-dd
>> HH:mm:ss} %-5p %X{username} %m%n"
>> 
>>
>> Best regards, Alex (abraxxa)
>>
>> On 2012-10-11 14:38, Robert Rothenberg wrote:
>>> I would like to trap every error added to $c->error() and log it, noting the
>>> caller (filename, line number) in the logs.
>>>
>>> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
>>> plugin that overrides $c->error with the following method:
>>>
>>>   use MRO::Compat;
>>>   use namespace::autoclean;
>>>
>>>   sub error {
>>> my ($c, @args) = @_;
>>>
>>> foreach my $arg (@args) {
>>> if ($arg) {
>>>
>>> $c->log->error($arg);
>>> }
>>> }
>>>
>>> return $c->next::method(@args);
>>>  }
>>>
>>> But this only logs errors as coming from my plugin.
>>>
>>> Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
>>> $Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.
>>>
>>> I also tried writing the plugin as a Moose::Role that adds my trap before
>>> error, but then it claims to be from one of the internal Moose classes in my
>>> logs.
>>>
>>> I can manually get the caller using caller(0) and add them to the log
>>> messages, but that's a bit clumsy (and overrides log formats that don't
>>> include the information).
>>>
>>> So... what is the best practice for trapping errors in a way that preserves
>>> caller information?
>>>
>>>
>>> ___
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/
>>
>>
>> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
>> Handelsgericht Wien, FN 79340b
>> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>> Notice: This e-mail contains information that is confidential and may be 
>> privileged.
>> If you are not the intended recipient, please notify the sender and then
>> delete this e-mail immediately.
>> *"*"*"*"*"*"*"*"*"*"*

Re: [Catalyst] Trapping added errors with the correct caller

2012-10-15 Thread Robert Rothenberg
On 15/10/12 15:21 Alexander Hartmaier wrote:
> I recommend to use a logging module like Log::Log4perl::Catalyst and do
> all your app logging there.

I use Log::Dispatch. (The application is already deployed, and it's not
feasible to change it to Log4perl now.)

I don't see where in your code you trap calls to $c->error() and log them.

> My log package for NAC::Web:NAC looks like this:
> 
> package NAC::Web::NAC::Log;
> use Moose;
> use Catalyst::Log;
> use namespace::autoclean;
> 
> BEGIN { extends 'Log::Log4perl::Catalyst'; }
> 
> =head1 NAME
> 
> NAC::Web::NAC::Log - Logger for NAC::Web::NAC
> 
> =cut
> 
> # import _dump method from Catalyst::Log
> *_dump = \&Catalyst::Log::_dump;
> 
> 1;
> 
> My app uses it with:
> 
> =item finalize_config
> 
> Initializes the logger after the config file merging and loading is done.
> 
> =cut
> 
> sub finalize_config {
> my $class = shift;
> $class->next::method(@_);
> $class->log(NAC::Web::NAC::Log->new($class->config->{log}));
> }
> 
> # Start the application
> __PACKAGE__->setup();
> 
> around 'prepare' => sub {
> my $orig = shift;
> my $self = shift;
> 
> Log::Log4perl::MDC->remove();
> 
> my $c = $self->$orig(@_);
> 
> Log::Log4perl::MDC->put( "username", $c->user->username )
> if $c->user_exists;
> 
> return $c;
> };
> 
> And this is how the app's prod config file looks like:
> 
> 
> log4perl.logger "WARN, FILE, MAIL"
> log4perl.appender.FILE
> "Log::Log4perl::Appender::File"
> log4perl.appender.FILE.filename
> "/home/nac/log/nac-web-nac.log"
> log4perl.appender.FILE.utf8 1
> log4perl.appender.FILE.syswrite 1
> log4perl.appender.FILE.layout
> "Log::Log4perl::Layout::PatternLayout"
> log4perl.appender.FILE.layout.ConversionPattern "%d{-MM-dd
> HH:mm:ss} %-5p %X{username} %m%n"
> log4perl.appender.MAIL
> "Log::Dispatch::Email::MailSend"
> log4perl.appender.MAIL.ThresholdERROR
> log4perl.appender.MAIL.from "n...@domain.com"
> log4perl.appender.MAIL.to
> "app-err...@domain.com"
> log4perl.appender.MAIL.subject  "[NAC::Web::NAC]
> errors"
> log4perl.appender.MAIL.buffered 0
> log4perl.appender.MAIL.layout   "PatternLayout"
> log4perl.appender.MAIL.layout.ConversionPattern "%d{-MM-dd
> HH:mm:ss} %-5p %X{username} %m%n"
> 
> 
> Best regards, Alex (abraxxa)
> 
> On 2012-10-11 14:38, Robert Rothenberg wrote:
>> I would like to trap every error added to $c->error() and log it, noting the
>> caller (filename, line number) in the logs.
>>
>> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
>> plugin that overrides $c->error with the following method:
>>
>>   use MRO::Compat;
>>   use namespace::autoclean;
>>
>>   sub error {
>> my ($c, @args) = @_;
>>
>> foreach my $arg (@args) {
>> if ($arg) {
>>
>> $c->log->error($arg);
>> }
>> }
>>
>> return $c->next::method(@args);
>>  }
>>
>> But this only logs errors as coming from my plugin.
>>
>> Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
>> $Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.
>>
>> I also tried writing the plugin as a Moose::Role that adds my trap before
>> error, but then it claims to be from one of the internal Moose classes in my
>> logs.
>>
>> I can manually get the caller using caller(0) and add them to the log
>> messages, but that's a bit clumsy (and overrides log formats that don't
>> include the information).
>>
>> So... what is the best practice for trapping errors in a way that preserves
>> caller information?
>>
>>
>> ___
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
> 
> 
> 
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> Handelsgericht Wien, FN 79340b
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> Notice: This e-mail contains information that is confidential and may be 
> privileged.
> If you are not the intended recipient, please notify the sender and then
> delete this e-mail immediately.
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> 
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.c

Re: [Catalyst] Trapping added errors with the correct caller

2012-10-15 Thread Alexander Hartmaier
I recommend to use a logging module like Log::Log4perl::Catalyst and do
all your app logging there.

My log package for NAC::Web:NAC looks like this:

package NAC::Web::NAC::Log;
use Moose;
use Catalyst::Log;
use namespace::autoclean;

BEGIN { extends 'Log::Log4perl::Catalyst'; }

=head1 NAME

NAC::Web::NAC::Log - Logger for NAC::Web::NAC

=cut

# import _dump method from Catalyst::Log
*_dump = \&Catalyst::Log::_dump;

1;

My app uses it with:

=item finalize_config

Initializes the logger after the config file merging and loading is done.

=cut

sub finalize_config {
my $class = shift;
$class->next::method(@_);
$class->log(NAC::Web::NAC::Log->new($class->config->{log}));
}

# Start the application
__PACKAGE__->setup();

around 'prepare' => sub {
my $orig = shift;
my $self = shift;

Log::Log4perl::MDC->remove();

my $c = $self->$orig(@_);

Log::Log4perl::MDC->put( "username", $c->user->username )
if $c->user_exists;

return $c;
};

And this is how the app's prod config file looks like:


log4perl.logger "WARN, FILE, MAIL"
log4perl.appender.FILE
"Log::Log4perl::Appender::File"
log4perl.appender.FILE.filename
"/home/nac/log/nac-web-nac.log"
log4perl.appender.FILE.utf8 1
log4perl.appender.FILE.syswrite 1
log4perl.appender.FILE.layout
"Log::Log4perl::Layout::PatternLayout"
log4perl.appender.FILE.layout.ConversionPattern "%d{-MM-dd
HH:mm:ss} %-5p %X{username} %m%n"
log4perl.appender.MAIL
"Log::Dispatch::Email::MailSend"
log4perl.appender.MAIL.ThresholdERROR
log4perl.appender.MAIL.from "n...@domain.com"
log4perl.appender.MAIL.to
"app-err...@domain.com"
log4perl.appender.MAIL.subject  "[NAC::Web::NAC]
errors"
log4perl.appender.MAIL.buffered 0
log4perl.appender.MAIL.layout   "PatternLayout"
log4perl.appender.MAIL.layout.ConversionPattern "%d{-MM-dd
HH:mm:ss} %-5p %X{username} %m%n"


Best regards, Alex (abraxxa)

On 2012-10-11 14:38, Robert Rothenberg wrote:
> I would like to trap every error added to $c->error() and log it, noting the
> caller (filename, line number) in the logs.
>
> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
> plugin that overrides $c->error with the following method:
>
>   use MRO::Compat;
>   use namespace::autoclean;
>
>   sub error {
> my ($c, @args) = @_;
>
> foreach my $arg (@args) {
> if ($arg) {
>
> $c->log->error($arg);
> }
> }
>
> return $c->next::method(@args);
>  }
>
> But this only logs errors as coming from my plugin.
>
> Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
> $Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.
>
> I also tried writing the plugin as a Moose::Role that adds my trap before
> error, but then it claims to be from one of the internal Moose classes in my
> logs.
>
> I can manually get the caller using caller(0) and add them to the log
> messages, but that's a bit clumsy (and overrides log formats that don't
> include the information).
>
> So... what is the best practice for trapping errors in a way that preserves
> caller information?
>
>
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

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


Re: [Catalyst] Trapping added errors with the correct caller

2012-10-11 Thread Robert Rothenberg
On 11/10/12 14:16 Bill Moseley wrote:
> 
> 
> On Thu, Oct 11, 2012 at 5:38 AM, Robert Rothenberg  > wrote:
> 
> 
> I would like to trap every error added to $c->error() and log it, noting 
> the
> caller (filename, line number) in the logs.
> 
> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
> plugin that overrides $c->error with the following method:
> 
>   use MRO::Compat;
>   use namespace::autoclean;
> 
>   sub error {
> my ($c, @args) = @_;
> 
> foreach my $arg (@args) {
> if ($arg) {
> 
> $c->log->error($arg);
> }
> }
> 
> 
> Isn't that what finalize already does?

I am using a custom error page.

More importantly: I also want to know where the error was triggered, hence
my question about using Sub::Uplevel.


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


Re: [Catalyst] Trapping added errors with the correct caller

2012-10-11 Thread Chisel
On Thu, Oct 11, 2012 at 1:38 PM, Robert Rothenberg  wrote:

>
> I would like to trap every error added to $c->error() and log it, noting
> the
> caller (filename, line number) in the logs.
>
> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
> plugin that overrides $c->error with the following method


I don't think Catalyst::Plugin::ErrorCatcher is quite what you need for
your requirement.

ErrorCatcher is basically ::Plugin::StackTrace with more options for where
the stack-trace should go (and some support for you to create more
destinations/behaviours).

It prepares (ok, munges in weird and wonderful ways) the output you would
see in the stacktrace plugin, and passes it on to pluggable modules for
them to 'emit' the prepared messages as they see fit.

It doesn't interact with $c->error() directly as far as I can remember.

-- 
Chisel
e: chi...@chizography.net
w: http://chizography.net
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Trapping added errors with the correct caller

2012-10-11 Thread Bill Moseley
On Thu, Oct 11, 2012 at 5:38 AM, Robert Rothenberg  wrote:

>
> I would like to trap every error added to $c->error() and log it, noting
> the
> caller (filename, line number) in the logs.
>
> I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
> plugin that overrides $c->error with the following method:
>
>   use MRO::Compat;
>   use namespace::autoclean;
>
>   sub error {
> my ($c, @args) = @_;
>
> foreach my $arg (@args) {
> if ($arg) {
>
> $c->log->error($arg);
> }
> }
>

Isn't that what finalize already does?

I have a very old and out-dated plugin I use that wraps execute() and sets
__DIE__ and __WARN__ to catch those and uses Devel::StackTrace to add in a
stack trace.   Then I use log4perl to format and direct the messages.

I also use Moose's Throwable which includes a stack trace.


-- 
Bill Moseley
mose...@hank.org
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Trapping added errors with the correct caller

2012-10-11 Thread Robert Rothenberg

I would like to trap every error added to $c->error() and log it, noting the
caller (filename, line number) in the logs.

I've not gotten Catalyst::Plugin::ErrorCatcher to work, so I wrote my own
plugin that overrides $c->error with the following method:

  use MRO::Compat;
  use namespace::autoclean;

  sub error {
my ($c, @args) = @_;

foreach my $arg (@args) {
if ($arg) {

$c->log->error($arg);
}
}

return $c->next::method(@args);
 }

But this only logs errors as coming from my plugin.

Using Sub::Uplevel or fiddling with $Log::Dispatch::CallerDepth or
$Catalyst::Plugin::Log::Dispatch::CallerDepth doesn't seem to work.

I also tried writing the plugin as a Moose::Role that adds my trap before
error, but then it claims to be from one of the internal Moose classes in my
logs.

I can manually get the caller using caller(0) and add them to the log
messages, but that's a bit clumsy (and overrides log formats that don't
include the information).

So... what is the best practice for trapping errors in a way that preserves
caller information?


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