]> SALOME platform Git repositories - tools/sat.git/blobdiff - src/logger.py
Salome HOME
get_salome_version returns integer, TODO use MajorMinorPatch
[tools/sat.git] / src / logger.py
index f50ae77e85510555dd0b6eee0bffbe8d8023fe92..49a8502c6ba735612736dfb811c7737c4a996013 100755 (executable)
@@ -22,6 +22,7 @@ Implements the classes and method relative to the logging
 
 import sys
 import os
+import stat
 import datetime
 import re
 import tempfile
@@ -70,8 +71,22 @@ class Logger(object):
         # the external commands calls (cmake, make, git clone, etc...)
         txtFileName = prefix + hour_command_host + ".txt"
         txtFilePath = os.path.join(log_dir, "OUT", txtFileName)
-        
-        src.ensure_path_exists(os.path.dirname(logFilePath))
+
+        aDirLog = os.path.dirname(logFilePath)
+        if not os.path.exists(aDirLog):
+          print("create log dir %s" % aDirLog)
+          src.ensure_path_exists(aDirLog)
+          # sometimes other users make 'sat log' and create hat.xml file...
+          os.chmod(aDirLog,
+                   stat.S_IRUSR |
+                   stat.S_IRGRP |
+                   stat.S_IROTH |
+                   stat.S_IWUSR |
+                   stat.S_IWGRP |
+                   stat.S_IWOTH |
+                   stat.S_IXUSR |
+                   stat.S_IXGRP |
+                   stat.S_IXOTH)
         src.ensure_path_exists(os.path.dirname(txtFilePath))
         
         # The path of the log files (one for sat traces, and the other for 
@@ -201,20 +216,57 @@ class Logger(object):
                 sys.stdout.write(message)
         self.flush()
 
-    def error(self, message):
-        """Print an error.
-        
-        :param message str: The message to print.
-        """
-        # Print in the log file
-        self.xmlFile.append_node_text("traces", _('ERROR:') + message)
+    def error(self, message, prefix="ERROR: "):
+      """Print an error.
+
+      :param message str: The message to print.
+      """
+      # Print in the log file
+      self.xmlFile.append_node_text("traces", prefix + message)
+
+      # Print in the terminal and clean colors if the terminal
+      # is redirected by user
+      if not ('isatty' in dir(sys.stderr) and sys.stderr.isatty()):
+        sys.stderr.write(printcolors.printcError(prefix + message + "\n"))
+      else:
+        sys.stderr.write(prefix + message + "\n")
+
+    def step(self, message):
+      """Print an step message.
+
+      :param message str: The message to print.
+      """
+      self.write('STEP: ' + message, level=4)
+
+    def trace(self, message):
+      """Print an trace message.
+
+      :param message str: The message to print.
+      """
+      self.write('TRACE: ' + message, level=5)
+
+    def debug(self, message):
+      """Print an debug message.
+
+      :param message str: The message to print.
+      """
+      self.write('DEBUG: ' + message, level=6)
+
+    def warning(self, message):
+      """Print an warning message.
+
+      :param message str: The message to print.
+      """
+      self.error(message, prefix="WARNING: ")
+
+    def critical(self, message):
+      """Print an critical message.
+
+      :param message str: The message to print.
+      """
+      self.error(message, prefix="CRITICAL: ")
+
 
-        # Print in the terminal and clean colors if the terminal 
-        # is redirected by user
-        if not ('isatty' in dir(sys.stderr) and sys.stderr.isatty()):
-            sys.stderr.write(printcolors.printcError(_('ERROR:') + message))
-        else:
-            sys.stderr.write(_('ERROR:') + message)
 
     def flush(self):
         """Flush terminal"""
@@ -413,8 +465,7 @@ def update_hat_xml(logDir, application=None, notShownCommands = []):
     """
     # Create an instance of XmlLogFile class to create hat.xml file
     xmlHatFilePath = os.path.join(logDir, 'hat.xml')
-    xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath,
-                                    "LOGlist", {"application" : application})
+    xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application})
     # parse the log directory to find all the command logs, 
     # then add it to the xml file
     lLogFile = list_log_file(logDir, log_macro_command_file_expression)
@@ -434,6 +485,15 @@ def update_hat_xml(logDir, application=None, notShownCommands = []):
     
     # Write the file on the hard drive
     xmlHat.write_tree('hat.xsl')
+    # Sometimes other users will make 'sat log' and update this file
+    os.chmod(xmlHatFilePath,
+             stat.S_IRUSR |
+             stat.S_IRGRP |
+             stat.S_IROTH |
+             stat.S_IWUSR |
+             stat.S_IWGRP |
+             stat.S_IWOTH )
+
 
 
 # TODO for future
@@ -468,7 +528,7 @@ def setCurrentLogger(logger):
   """temporary send all in stdout as simple logging logger"""
   if len(_currentLogger) == 0:
     _currentLogger.append(logger)
-    logger.warning("set current logger as %s" % logger.name)
+    logger.debug("set current logger as %s" % logger.name)
   else:
     if _currentLogger[0].name != logger.name:
       # logger.debug("quit current logger as default %s" % _currentLogger[0].name)