Exemple #1
0
    def _log(self,
             level,
             msg,
             args,
             exc_info=None,
             extra=None,
             codepath=None,
             activateLogViewer=False,
             stack_info=None):
        if not extra:
            extra = {}

        if not codepath or stack_info is True:
            f = inspect.currentframe().f_back.f_back

        if not codepath:
            codepath = getCodePath(f)
        extra["codepath"] = codepath

        if not globalVars.appArgs or globalVars.appArgs.secure:
            # The log might expose sensitive information and the Save As dialog in the Log Viewer is a security risk.
            activateLogViewer = False

        if activateLogViewer:
            # Import logViewer here, as we don't want to import GUI code when this module is imported.
            from gui import logViewer
            logViewer.activate()
            # Move to the end of the current log text. The new text will be written at this position.
            # This means that the user will be positioned at the start of the new log text.
            # This is why we activate the log viewer before writing to the log.
            logViewer.logViewer.outputCtrl.SetInsertionPointEnd()

        if stack_info:
            if stack_info is True:
                stack_info = traceback.extract_stack(f)
            msg += ("\nStack trace:\n" + stripBasePathFromTracebackText(
                "".join(traceback.format_list(stack_info)).rstrip()))

        try:
            msg = re.sub(r"\\u([0-9a-f]{4})",
                         lambda x: unichr(int("0x" + x.group(1), 16)),
                         unicode(msg))
        except:
            pass
        res = logging.Logger._log(self, level, msg, args, exc_info, extra)

        if activateLogViewer:
            # Make the log text we just wrote appear in the log viewer.
            logViewer.logViewer.refresh()

        return res
Exemple #2
0
	def _log(self, level, msg, args, exc_info=None, extra=None, codepath=None, activateLogViewer=False, stack_info=None):
		if not extra:
			extra={}

		if not codepath or stack_info is True:
			f=inspect.currentframe().f_back.f_back

		if not codepath:
			codepath=getCodePath(f)
		extra["codepath"] = codepath

		if not globalVars.appArgs or globalVars.appArgs.secure:
			# The log might expose sensitive information and the Save As dialog in the Log Viewer is a security risk.
			activateLogViewer = False

		if activateLogViewer:
			# Import logViewer here, as we don't want to import GUI code when this module is imported.
			from gui import logViewer
			logViewer.activate()
			# Move to the end of the current log text. The new text will be written at this position.
			# This means that the user will be positioned at the start of the new log text.
			# This is why we activate the log viewer before writing to the log.
			logViewer.logViewer.outputCtrl.SetInsertionPointEnd()

		if stack_info:
			if stack_info is True:
				stack_info = traceback.extract_stack(f)
			msg += ("\nStack trace:\n"
				+ stripBasePathFromTracebackText("".join(traceback.format_list(stack_info)).rstrip()))

		res = logging.Logger._log(self,level, msg, args, exc_info, extra)

		if activateLogViewer:
			# Make the log text we just wrote appear in the log viewer.
			logViewer.logViewer.refresh()

		return res