From 19168ee48c634baf7cf6e23e6b19686e76e54af8 Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Tue, 1 Jul 2014 15:53:23 +0100
Subject: [PATCH] improved and simplified logging/reporting

---
 modules/Bio/EnsEMBL/Hive/AnalysisJob.pm | 22 ------------
 modules/Bio/EnsEMBL/Hive/Process.pm     | 47 +++++++++++++++++++------
 modules/Bio/EnsEMBL/Hive/Worker.pm      |  6 ++--
 3 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm b/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
index 89d49059f..4db6a33a5 100644
--- a/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
+++ b/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
@@ -238,28 +238,6 @@ sub died_somewhere {
 
 ##-----------------[/indicators to the Worker]-------------------------------
 
-=head2 warning
-
-    Description:    records a non-error message in 'log_message' table linked to the current job
-
-=cut
-
-sub warning {
-    my ($self, $msg, $is_error) = @_;
-
-    $is_error //= 0;
-    my $job_adaptor = $self->adaptor;
-
-    if( $is_error or !$job_adaptor) {
-        my $class = $is_error ? 'Error' : 'Warning';
-        print STDERR "Job${class}: $msg\n";
-    }
-
-    if( $job_adaptor ) {
-        $job_adaptor->db->get_LogMessageAdaptor()->store_job_message($self->dbID, $msg, $is_error);
-    }
-}
-
 
 sub fan_cache {     # a self-initializing getter (no setting)
                     # Returns a hash-of-lists { 2 => [list of jobs waiting to be funneled into 2], 3 => [list of jobs waiting to be funneled into 3], etc}
diff --git a/modules/Bio/EnsEMBL/Hive/Process.pm b/modules/Bio/EnsEMBL/Hive/Process.pm
index 7386d9e1f..935dff3a8 100644
--- a/modules/Bio/EnsEMBL/Hive/Process.pm
+++ b/modules/Bio/EnsEMBL/Hive/Process.pm
@@ -145,7 +145,7 @@ sub life_cycle {
             $self->write_output;
             $job_partial_timing{'WRITE_OUTPUT'} = $partial_stopwatch->get_elapsed();
         } else {
-            print STDERR "\n!!! *no* WRITE_OUTPUT requested, so there will be no AUTOFLOW\n" if($self->debug); 
+            $self->say_with_header( ": *no* WRITE_OUTPUT requested, so there will be no AUTOFLOW" );
         }
     };
 
@@ -169,7 +169,7 @@ sub life_cycle {
     unless( $job->died_somewhere ) {
 
         if( $self->execute_writes and $job->autoflow ) {    # AUTOFLOW doesn't have its own status so will have whatever previous state of the job
-            print STDERR "\njob ".$job->dbID." : AUTOFLOW input->output\n" if($self->debug);
+            $self->say_with_header( ': AUTOFLOW input->output' );
             $job->dataflow_output_id();
         }
 
@@ -186,6 +186,21 @@ sub life_cycle {
 }
 
 
+sub say_with_header {
+    my ($self, $msg, $important) = @_;
+
+    $important //= $self->debug();
+
+    if($important) {
+        if(my $worker = $self->worker) {
+            $worker->worker_say( $msg );
+        } else {
+            print STDERR "StandaloneJob $msg\n";
+        }
+    }
+}
+
+
 sub enter_status {
     my ($self, $status) = @_;
 
@@ -194,9 +209,25 @@ sub enter_status {
     $job->set_and_update_status( $status );
 
     if(my $worker = $self->worker) {
-        $worker->enter_status( $status );
-    } elsif($self->debug) {
-        print STDERR "StandaloneJob : $status\n";
+        $worker->set_and_update_status( $status );
+    }
+
+    $self->say_with_header( '-> '.$status );
+}
+
+
+sub warning {
+    my ($self, $msg, $is_error) = @_;
+
+    $is_error //= 0;
+    chomp $msg;
+
+    $self->say_with_header( ($is_error ? 'Fatal' : 'Warning')." : $msg" );
+
+    my $job = $self->input_job;
+
+    if(my $job_adaptor = $job->adaptor) {
+        $job_adaptor->db->get_LogMessageAdaptor()->store_job_message($job->dbID, $msg, $is_error);
     }
 }
 
@@ -471,12 +502,6 @@ sub param_substitute {
     return $self->input_job->param_substitute(@_);
 }
 
-sub warning {
-    my $self = shift @_;
-
-    return $self->input_job->warning(@_);
-}
-
 sub dataflow_output_id {
     my $self = shift @_;
 
diff --git a/modules/Bio/EnsEMBL/Hive/Worker.pm b/modules/Bio/EnsEMBL/Hive/Worker.pm
index e33048ecb..1392fecca 100644
--- a/modules/Bio/EnsEMBL/Hive/Worker.pm
+++ b/modules/Bio/EnsEMBL/Hive/Worker.pm
@@ -743,12 +743,10 @@ sub set_and_update_status {
 
 
 sub enter_status {
-    my ($self, $status, $msg) = @_;
-
-    $msg ||= ": $status";
+    my ($self, $status) = @_;
 
     if($self->debug) {
-        $self->worker_say( $msg );
+        $self->worker_say( '-> '.$status );
     }
 
     $self->set_and_update_status( $status );
-- 
GitLab