2

How can I make sure that I see all of Perl's warning and error messages when running a script under mod_perl? (Apache/2.2.16 (Debian) [...] mod_perl/2.0.4 Perl/v5.10.1)

I feel like I have done everything correctly: I have "PerlWarn On" in httpd.conf, I have

use strict;
use warnings FATAL => 'all';

in all my Perl files, and when I myself use warn(), I see the result in /var/log/apache2/error.log.

But many messages still don't get to me. For instance, "Can't locate object method" never appears in the log. The script simply dies and I have to figure out for myself where and why.

Anything I may have overlooked?

scozy
  • 2,511
  • 17
  • 34
  • Are `$SIG{__WARN__}` and `$SIG{__DIE__}` being overridden in some of your scripts? – Zaid Jan 30 '13 at 14:52
  • No, I didn't touch any signal handling. – scozy Jan 30 '13 at 15:07
  • The requests are handled by Apache2::Controller::Dispatch::Simple, the controllers are Apache2::Controller+Apache2::Request, and the rest is pretty much my own code. No CGI module. – scozy Jan 30 '13 at 15:12
  • Replacing `use warnings FATAL => 'all';` with `use warnings;` in the module where the problem happened made the warning appear in error.log. Is it possible that something about `FATAL => all` make the script die before it gets a chance at printing to STDERR? – scozy Jan 30 '13 at 16:14

1 Answers1

1

The statement

use warnings FATAL => 'all';

is a lexical warnings pragma. It only applies to the current block (in this case your script), and not modules or other files that your script calls.

Look into Carp::Always to get this kind of behavior across all of your code for debugging purposes.

  • 1
    You could also do a `use Carp; local $SIG{__WARN__} = \&Carp::cluck;` – Zaid Jan 30 '13 at 15:28
  • @Zaid, wouldn't that only apply to the current file, just like the problem he is having? –  Jan 30 '13 at 15:32
  • It's good to know about Carp::Always. It did print extra information in the logs about the warnings I was seeing already (the ones I generate myself with warn), but unfortunately no new warning appeared. – scozy Jan 30 '13 at 15:46
  • @scozy, perhaps some module somewhere is doing something funny with warnings? –  Jan 30 '13 at 15:54
  • @dan1111 : I use it all the time and it should work as long as the calling script you place it in is part of the stacktrace. – Zaid Jan 30 '13 at 17:10