Exemplo n.º 1
0
def Warn(ToolName, Message, File=None, Line=None, ExtraData=None):
    if _INFO_LOGGER.level > WARN:
        return
    #
    # if no tool name given, use caller's source file name as tool name
    #
    if ToolName is None or ToolName == "":
        ToolName = os.path.basename(extract_stack()[-2][0])

    if Line is None:
        Line = "..."
    else:
        Line = "%d" % Line

    TemplateDict = {
        "tool": ToolName,
        "file": File,
        "line": Line,
        "msg": Message,
    }

    if File is not None:
        LogText = _WARNING_MESSAGE_TEMPLATE % TemplateDict
    else:
        LogText = _WARNING_MESSAGE_TEMPLATE_WITHOUT_FILE % TemplateDict

    if ExtraData is not None:
        LogText += "\n    %s" % ExtraData

    _INFO_LOGGER.log(WARN, LogText)
    #
    # Raise an execption if indicated
    #
    if GlobalData.gWARNING_AS_ERROR == True:
        raise FatalError(WARNING_AS_ERROR)
Exemplo n.º 2
0
def Error(ToolName, ErrorCode, Message=None, File=None, Line=None, \
          ExtraData=None, RaiseError=IS_RAISE_ERROR):
    if ToolName:
        pass
    if Line is None:
        Line = "..."
    else:
        Line = "%d" % Line

    if Message is None:
        if ErrorCode in gERROR_MESSAGE:
            Message = gERROR_MESSAGE[ErrorCode]
        else:
            Message = gERROR_MESSAGE[UNKNOWN_ERROR]

    if ExtraData is None:
        ExtraData = ""

    TemplateDict = {
        "tool": _TOOL_NAME,
        "file": File,
        "line": Line,
        "errorcode": ErrorCode,
        "msg": Message,
        "extra": ExtraData
    }

    if File is not None:
        LogText = _ERROR_MESSAGE_TEMPLATE % TemplateDict
    else:
        LogText = __ERROR_MESSAGE_TEMPLATE_WITHOUT_FILE % TemplateDict

    if not SUPRESS_ERROR:
        _ERROR_LOGGER.log(ERROR, LogText)
    if RaiseError:
        raise FatalError(ErrorCode)