You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2004/09/09 18:58:08 UTC

cvs commit: modperl-2.0/xs/Apache/ServerRec ServerRec_pm

stas        2004/09/09 09:58:08

  Modified:    .        Changes
               xs/Apache/Log Apache__Log.h
  Added:       t/response/TestVhost log.pm
               t/vhost  log.t
               t/htdocs/vhost .cvsignore
               xs/Apache/ServerRec ServerRec_pm
  Log:
  - fix Apache::ServerRec::warn()
  - make Apache::ServerRec::warn exportable
  - test Apache::Log for vhosts
  
  Revision  Changes    Path
  1.1                  modperl-2.0/t/response/TestVhost/log.pm
  
  Index: log.pm
  ===================================================================
  package TestVhost::log;
  
  # testing that the warn and other logging functions are writing into
  # the vhost error_log and not the main one.
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::RequestUtil ();
  
  use Apache::ServerRec qw(warn); # override warn locally
  
  use File::Spec::Functions qw(catfile);
  use POSIX ();
  use Symbol ();
  
  use Apache::Const -compile => 'OK';
  
  my @methods1 = (
      '$r->log->warn',
      '$r->log_error',
      '$s->log->warn',
      '$s->log_error',
      '$s->warn',
  );
  
  my @methods2 = (
      'Apache->warn',
      'Apache::ServerRec->warn',
      'Apache::ServerRec::warn',
      'Apache::warn',
      'warn',
  );
  
  my $path = catfile Apache::Test::vars('documentroot'),
      qw(vhost error_log);
  my $fh;
  my $pos;
  
  sub handler {
      my $r = shift;
  
      plan $r, tests => 1 + @methods1 + @methods2;
  
      my $s = $r->server;
  
      $fh = Symbol::gensym();
      open $fh, "<$path" or die "Can't open $path: $!";
      seek $fh, 0, POSIX::SEEK_END();
      $pos = tell $fh;
  
      ### $r|$s logging
      for my $m (@methods1) {
          eval "$m(q[$m])";
          check($m);
      }
  
      ### object-less logging
      # set Apache->request($r) instead of using
      #   PerlOptions +GlobalRequest
      # in order to make sure that the above tests work fine,
      # w/o having the global request set
      Apache->request($r);
      for my $m (@methods2) {
          eval "$m(q[$m])";
          check($m);
      }
  
      # internal warnings (also needs +GlobalRequest)
      {
          no warnings; # avoid FATAL warnings
          use warnings;
          local $SIG{__WARN__}= \&Apache::ServerRec::warn;
          eval q[my $x = "aaa" + 1;];
          check(q[Argument "aaa" isn't numeric in addition])
      }
  
      # die logs into the vhost log just fine
      #die "horrible death!";
  
      close $fh;
  
      Apache::OK;
  }
  
  sub check {
      my $find = shift;
      $find = ref $find eq 'Regexp' ? $find : qr/\Q$find/;
      my $diff = diff();
      ok t_cmp $diff, $find;
  }
  
  # extract any new logged information since the last check, move the
  # filehandle to the end of the file
  sub diff {
      # XXX: is it possible that some system will be slow to flush the
      # buffers and we may need to wait a bit and retry if we get see
      # no new logged data?
      seek $fh, $pos, POSIX::SEEK_SET(); # not really needed
      local $/; # slurp mode
      my $diff = <$fh>;
      seek $fh, 0, POSIX::SEEK_END();
      $pos = tell $fh;
      return defined $diff ? $diff : '';
  }
  
  1;
  __END__
  <NoAutoConfig>
  <VirtualHost TestVhost::log>
      DocumentRoot @documentroot@/vhost
      ErrorLog @documentroot@/vhost/error_log
  
      <Location /TestVhost__log>
          SetHandler modperl
          # required when $s and $r aren't passed
          PerlOptions +GlobalRequest
          PerlResponseHandler TestVhost::log
      </Location>
  
  </VirtualHost>
  </NoAutoConfig>
  
  
  
  1.1                  modperl-2.0/t/vhost/log.t
  
  Index: log.t
  ===================================================================
  use Apache::TestUtil;
  use Apache::TestRequest 'GET_BODY_ASSERT';
  
  my $config = Apache::Test::config();
  my $vars = $config->{vars};
  
  my $module = 'TestVhost::log';
  my $path = Apache::TestRequest::module2path($module);
  
  Apache::TestRequest::module($module);
  my $hostport = Apache::TestRequest::hostport($config);
  
  t_debug("connecting to $hostport");
  print GET_BODY_ASSERT "http://$hostport/$path";
  
  
  
  
  1.1                  modperl-2.0/t/htdocs/vhost/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  error_log
  
  
  
  1.477     +8 -3      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.476
  retrieving revision 1.477
  diff -u -u -r1.476 -r1.477
  --- Changes	9 Sep 2004 15:08:03 -0000	1.476
  +++ Changes	9 Sep 2004 16:58:08 -0000	1.477
  @@ -15,6 +15,14 @@
   introduce a custom modperl error message for failing filter handlers
   (previously 'unknown error' coming from rc=500 was logged) [Stas]
   
  +Fix Apache::Log methods/functions to log into the vhost's error_log
  +file (if there is one). ( $s->log->*, $s->log_error, $s->log_serror,
  +Apache::ServerRec::warn, etc.). Apache::ServerRec can now export its
  +warn function to override CORE::warn [Stas]
  +
  +Fix $s->log->*, $s->log_error and $s->log_serror to again log into the
  +vhost's error_log file (if there is one). [Stas]
  +
   $s->log->warn and other $s->log->foo are now logging to the right
   vhost server and not the global one. modperl_sv2server_rec was
   broken. [Stas]
  @@ -45,9 +53,6 @@
   fix the modperl build, where httpd has been built against separate
   installations of apr-util and apr, where apr-util has been installed
   with a different includedir to apr. [Joe Orton]
  -
  -Fix $s->log->*, $s->log_error and $s->log_serror to again log into the
  -vhost's error_log file (if there is one). [Stas]
   
   $Apache::Server::SaveConfig is now $Apache::PerlSections::Save
   [Geoffrey Young]
  
  
  
  1.19      +3 -1      modperl-2.0/xs/Apache/Log/Apache__Log.h
  
  Index: Apache__Log.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/Apache/Log/Apache__Log.h,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -u -r1.18 -r1.19
  --- Apache__Log.h	8 Sep 2004 23:41:53 -0000	1.18
  +++ Apache__Log.h	9 Sep 2004 16:58:08 -0000	1.19
  @@ -308,7 +308,9 @@
           i = 1;
       }
       else {
  -        s = modperl_global_get_server_rec();
  +        request_rec *r = NULL;
  +        (void)modperl_tls_get_request_rec(&r);
  +        s = r ? r->server : modperl_global_get_server_rec();
       }
   
       if (items > 1+i) {
  
  
  
  1.1                  modperl-2.0/xs/Apache/ServerRec/ServerRec_pm
  
  Index: ServerRec_pm
  ===================================================================
  use Exporter ();
  use Apache::Log (); # Apache::ServerRec::loads warn
  @Apache::ServerRec::EXPORT_OK = qw(warn);
  *Apache::ServerRec::import = \&Exporter::import;