Debug : when BEREMIZ_DEBUG file exist, display all commands issued in console.
authorEdouard Tisserant
Fri, 12 Jun 2020 14:40:50 +0200
changeset 2671 30493ff3a23a
parent 2670 fd348d79a1f3
child 2672 4bc60e426dd6
Debug : when BEREMIZ_DEBUG file exist, display all commands issued in console.
util/ProcessLogger.py
--- a/util/ProcessLogger.py	Fri Jun 12 14:39:32 2020 +0200
+++ b/util/ProcessLogger.py	Fri Jun 12 14:40:50 2020 +0200
@@ -31,6 +31,7 @@
 from threading import Timer, Lock, Thread, Semaphore
 import signal
 
+_debug = os.path.exists("BEREMIZ_DEBUG")
 
 class outputThread(Thread):
     """
@@ -77,6 +78,7 @@
                  timeout=None, outlimit=None, errlimit=None,
                  endlog=None, keyword=None, kill_it=False, cwd=None,
                  encoding=None, output_encoding=None):
+        assert(logger)
         self.logger = logger
         if not isinstance(Command, list):
             self.Command_str = Command
@@ -174,8 +176,9 @@
             self.endlog()
 
     def log_the_end(self, ecode, pid):
-        self.logger.write(self.Command_str + "\n")
-        self.logger.write_warning(_("exited with status {a1} (pid {a2})\n").format(a1=str(ecode), a2=str(pid)))
+        if self.logger is not None:
+            self.logger.write(self.Command_str + "\n")
+            self.logger.write_warning(_("exited with status {a1} (pid {a2})\n").format(a1=str(ecode), a2=str(pid)))
 
     def finish(self, pid, ecode):
         # avoid running function before start is finished
@@ -184,7 +187,7 @@
         if self.timeout:
             self.timeout.cancel()
         self.exitcode = ecode
-        if self.exitcode != 0:
+        if _debug or self.exitcode != 0:
             self.log_the_end(ecode, pid)
         if self.finish_callback is not None:
             self.finish_callback(self, ecode, pid)