class Logger(object):
'''Class to handle log mechanism.
'''
- def __init__(self, config, silent_sysstd=False, all_in_terminal=False):
+ def __init__(self,
+ config,
+ silent_sysstd=False,
+ all_in_terminal=False,
+ micro_command = False):
'''Initialization
:param config pyconf.Config: The global configuration.
self.silentSysStd = silent_sysstd
# Construct xml log file location for sat prints.
- logFileName = config.VARS.datehour + "_" + config.VARS.command + ".xml"
- logFilePath = os.path.join(config.SITE.log.log_dir, logFileName)
+ prefix = ""
+ if micro_command:
+ prefix = "micro_"
+ hour_command = config.VARS.datehour + "_" + config.VARS.command
+ logFileName = prefix + hour_command + ".xml"
+ logFilePath = os.path.join(config.USER.log_dir, logFileName)
# Construct txt file location in order to log
# the external commands calls (cmake, make, git clone, etc...)
- txtFileName = config.VARS.datehour + "_" + config.VARS.command + ".txt"
- txtFilePath = os.path.join(config.SITE.log.log_dir, "OUT", txtFileName)
+ txtFileName = prefix + hour_command + ".txt"
+ txtFilePath = os.path.join(config.USER.log_dir, "OUT", txtFileName)
src.ensure_path_exists(os.path.dirname(logFilePath))
src.ensure_path_exists(os.path.dirname(txtFilePath))
else:
if self.default_level <= current_output_verbose_level and not self.silentSysStd:
sys.stdout.write(message)
+ self.flush()
def error(self, message):
'''Print an error.
self.xmlFile.write_tree(stylesheet = "command.xsl")
# Dump the config in a pyconf file in the log directory
- logDir = self.config.SITE.log.log_dir
+ logDir = self.config.USER.log_dir
dumpedPyconfFileName = (self.config.VARS.datehour
+ "_"
+ self.config.VARS.command
return False, None
# Get the application of the log file
- logFileXml = src.xmlManager.ReadXmlFile(logFilePath)
+ try:
+ logFileXml = src.xmlManager.ReadXmlFile(logFilePath)
+ except Exception as e:
+ msg = _("WARNING: the log file %s cannot be read:" % logFilePath)
+ sys.stdout.write(printcolors.printcWarning("%s\n%s\n" % (msg, e)))
+ return False, None
if 'application' in logFileXml.xmlroot.keys():
appliLog = logFileXml.xmlroot.get('application')