fenLisesi has asked for the wisdom of the Perl Monks concerning the following question:

O wise ones,

Humbled, as always, at your presence, I seek your wisdom on a problem that we are having, trying to maintain our web application on Windows systems. The following is a description of the issue that my colleague has put together.

Abstract

Enabling mod_perl in my Win32 environment causes Perl warnings to disappear. Warnings from CORE and those from explicit "warn" api calls don't appear in error.log, although "die" messages do appear. There is no problem when operating in plain CGI mode. There is no problem with the application running on Linux, mod_perl or otherwise.

Platform details

httpd.conf contents

... ThreadsPerChild 100 MaxRequestsPerChild 0 ... ErrorLog logs/error.log ... LogLevel warn ...

Some tests

When warn is aliased to Apache2::ServerRec::warn, like
*CORE::GLOBAL::warn = \&Apache2::ServerRec::warn;
messages are recorded in error.log. However, in order to have all STDERR messages (like, perl warnings etc.) recorded in error.log, i've tried
local $SIG{__WARN__} = \&Apache2::ServerRec::warn;
But it doesn't work, maybe since alarms are not reliable in Win32.

Apache's loglevel is "warn", (i verified that by inspecting loglevel at runtime by: $loglevel = $s->loglevel();)

Please have a look at the code segment below, when warn is redirected to mywarn

use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(ENOTIME SUCCESS); *CORE::GLOBAL::warn = \&mywarn; sub mywarn { my @msg = @_; my $s = Apache2::ServerUtil->server; $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING, APR::Const::SUCCESS, @msg); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR, APR::Const::SUCCESS, @msg); }
Each "warn" message appears twice as expected: first as a [warn], next as an [error]. So I shouldn't have a problem with LogLevel in httpd.conf, since warnings appear without a problem.

How can I enable STDERR messages to appear in error.log in a Win32 environment?

I would prefer not to introduce such hacks to warn, carp etc either.

Replies are listed 'Best First'.
Re: Warnings awol in Win32 mod_perl.
by glasswalk3r (Friar) on Apr 26, 2007 at 12:52 UTC

    Although I'm unable to tell why is not working, I think I can give you at least a workaround: why don't you use Log4perl instead of relying in warn going to Apache log´s? Even if you start using just the "fast and dirty" mode, I think is worth of it.

    By experience, using WindowsXP to do anything that you would like to do in a server is a problem. Things just don't work like they are suppose to, like FastCGI and Cygwin, for example. You may want to check the possibility to use a differente version of Windows or use IIS with the ActivePerl binding (PerlEx) to get the speed improvement.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
      I guess we will consider Log::Log4perl and similar options if all else fails, unless, the consensus here is that I should be using them in any case. I would have to study whether such workarounds would recover warnings from perl as well.

      XP is my friend's dev environment. The internal staging deployment is on 2003 Server and we see the same behavior there, too.

Re: Warnings awol in Win32 mod_perl.
by Trizor (Pilgrim) on Apr 26, 2007 at 19:02 UTC

    This seems to be an apache configuration problem. I can't remember the directive off the top of my head but there is a configuration directive to place in httpd.conf or whatever your conf file scheme is to tell apache what severity of error should make it to error.log. IIRC you can obtain a very fine grain of control over what errors are logged where.