From 945e1ddc24c037e84a375766b56533062576efbd Mon Sep 17 00:00:00 2001
From: lb584 <lb584@cam.ac.uk>
Date: Wed, 10 Apr 2024 11:32:56 +0100
Subject: [PATCH] adding console logging (streamhandler) so outout sent to
 loggers is also sent to the screen (useful for Airflow to pick up and display
 in its logs)

---
 coordinator/Processor.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/coordinator/Processor.py b/coordinator/Processor.py
index b99653c..9341f71 100755
--- a/coordinator/Processor.py
+++ b/coordinator/Processor.py
@@ -156,6 +156,13 @@ class Processor:
                     'filename':  job_log_file_path,
                     'mode':      'a',  # 'a' for append
                 },
+                # logging for job to stderr (useful for Airflow to catch in its logs)
+                'handler_stderr':           {
+                    'class':     'logging.StreamHandler',
+                    'level':     'INFO',
+                    'formatter': 'simple',
+                    'filters':   ['mask_passwords']
+                },
                 # to email errors to maintainers
                 'handler_buffered_email': {
                     'class':       'BufferingSMTPHandler.BufferingSMTPHandler',
@@ -176,7 +183,7 @@ class Processor:
                 # i.e. with logging.getLogger('Process.')
                 script_name: {
                     'level':     'INFO',
-                    'handlers':  ['handler_rot_file', 'handler_file', 'handler_buffered_email'],
+                    'handlers':  ['handler_rot_file', 'handler_file', 'handler_buffered_email', 'handler_stderr'],
                     'propagate': True,
                 },
                 # this is activated when this script is called on the command line
@@ -184,7 +191,7 @@ class Processor:
                 # i.e. with logging.getLogger(__name__) when name == '__main__'
                 '__main__':  {
                     'level':     'INFO',
-                    'handlers':  ['handler_rot_file', 'handler_file', 'handler_buffered_email'],
+                    'handlers':  ['handler_rot_file', 'handler_file', 'handler_buffered_email', 'handler_stderr'],
                     'propagate': True,
                 }
             }
-- 
GitLab