[Opensrf-commits] r2035 - in trunk: examples src/perl/lib/OpenSRF (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Oct 12 10:53:43 EDT 2010


Author: erickson
Date: 2010-10-12 10:53:41 -0400 (Tue, 12 Oct 2010)
New Revision: 2035

Modified:
   trunk/examples/opensrf.xml.example
   trunk/src/perl/lib/OpenSRF/Server.pm
   trunk/src/perl/lib/OpenSRF/System.pm
Log:
implemented an optional per-service stderr log for capturing miscellaneous stderr output from services, similar to the old-style _unix.log files, since there are often useful warnings and error messages that never bubble up to syslog.  for clarity, the files now use _stderr as a suffix instead of _unix.  stderr logs are enabled by default.  included opensrf.xml example of how to disable it for a given service

Modified: trunk/examples/opensrf.xml.example
===================================================================
--- trunk/examples/opensrf.xml.example	2010-10-12 02:59:37 UTC (rev 2034)
+++ trunk/examples/opensrf.xml.example	2010-10-12 14:53:41 UTC (rev 2035)
@@ -90,6 +90,9 @@
         <!-- max stateful requests before a session automatically disconnects a client -->
         <max_requests>97</max_requests>
 
+        <!-- this will disable the stderr output log for this service -->
+        <!--<diable_stderr>true</disable_stderr>-->
+
         <!-- settings for the backend application drones.  These are probably sane defaults -->
         <unix_config>
 

Modified: trunk/src/perl/lib/OpenSRF/Server.pm
===================================================================
--- trunk/src/perl/lib/OpenSRF/Server.pm	2010-10-12 02:59:37 UTC (rev 2034)
+++ trunk/src/perl/lib/OpenSRF/Server.pm	2010-10-12 14:53:41 UTC (rev 2035)
@@ -34,13 +34,16 @@
     my($class, $service, %args) = @_;
     my $self = bless(\%args, $class);
 
-    $self->{service}         = $service; # service name
-    $self->{num_children}    = 0; # number of child processes
-    $self->{osrf_handle}     = undef; # xmpp handle
-    $self->{routers}         = []; # list of registered routers
-    $self->{active_list}     = []; # list of active children
-    $self->{idle_list}       = []; # list of idle children
+    $self->{service}        = $service; # service name
+    $self->{num_children}   = 0; # number of child processes
+    $self->{osrf_handle}    = undef; # xmpp handle
+    $self->{routers}        = []; # list of registered routers
+    $self->{active_list}    = []; # list of active children
+    $self->{idle_list}      = []; # list of idle children
 
+    $self->{stderr_log} = $self->{stderr_log_path} . "/${service}_stderr.log" 
+        if $self->{stderr_log_path};
+
     $self->{min_spare_children} ||= 0;
 
     $self->{max_spare_children} = $self->{min_spare_children} + 1 if
@@ -345,6 +348,17 @@
 
         $SIG{$_} = 'DEFAULT' for (qw/INT TERM QUIT HUP/);
 
+        if($self->{stderr_log}) {
+
+            $chatty and $logger->internal("server: redirecting STDERR to " . $self->{stderr_log});
+
+            close STDERR;
+            unless( open(STDERR, '>>' . $self->{stderr_log}) ) {
+                $logger->error("server: unable to open STDERR log file: " . $self->{stderr_log} . " : $@");
+                open STDERR, '>/dev/null'; # send it back to /dev/null
+            }
+        }
+
         $child->{pid} = $$;
         eval {
             $child->init;

Modified: trunk/src/perl/lib/OpenSRF/System.pm
===================================================================
--- trunk/src/perl/lib/OpenSRF/System.pm	2010-10-12 02:59:37 UTC (rev 2034)
+++ trunk/src/perl/lib/OpenSRF/System.pm	2010-10-12 14:53:41 UTC (rev 2035)
@@ -86,6 +86,10 @@
 
     # kill the temp connection
     OpenSRF::Transport::PeerHandle->retrieve->disconnect;
+    
+    # if this service does not want stderr output, it will be redirected to /dev/null
+    my $disable_stderr = $getval->('disable_stderr') || '';
+    my $stderr_path = ($disable_stderr =~ /true/i) ? undef : $sclient->config_value(dirs => 'log');
 
     my $server = OpenSRF::Server->new(
         $service,
@@ -94,7 +98,8 @@
         max_children =>  $getval->(unix_config => 'max_children') || 20,
         min_children =>  $getval->(unix_config => 'min_children') || 1,
         min_spare_children =>  $getval->(unix_config => 'min_spare_children'),
-        max_spare_children =>  $getval->(unix_config => 'max_spare_children')
+        max_spare_children =>  $getval->(unix_config => 'max_spare_children'),
+        stderr_log_path => $stderr_path
     );
 
     while(1) {



More information about the opensrf-commits mailing list