## @file
# This file implements the log mechanism for Python tools.
#
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
## Import modules
import traceback
from BuildToolError import *
## Log level constants
# Tool name
# For validation purpose
_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]
# For DEBUG level (All DEBUG_0~9 are applicable)
# For VERBOSE, INFO, WARN level
# For ERROR level
_ErrorMessageTemplate = '\n\n%(tool)s...\n%(file)s(%(line)s): error %(errorcode)04X: %(msg)s\n\t%(extra)s'
_ErrorMessageTemplateWithoutFile = '\n\n%(tool)s...\n : error %(errorcode)04X: %(msg)s\n\t%(extra)s'
#
# Flag used to take WARN as ERROR.
# By default, only ERROR message will break the tools execution.
#
## Log debug message
#
# @param Level DEBUG level (DEBUG0~9)
# @param Message Debug information
# @param ExtraData More information associated with "Message"
#
return
return
# Find out the caller method information
TemplateDict = {
"msg" : Message,
}
if ExtraData != None:
else:
## Log verbose message
#
# @param Message Verbose information
#
## Log warning message
#
# Warning messages are those which might be wrong but won't fail the tool.
#
# @param ToolName The name of the tool. If not given, the name of caller
# method will be used.
# @param Message Warning information
# @param File The name of file which caused the warning.
# @param Line The line number in the "File" which caused the warning.
# @param ExtraData More information associated with "Message"
#
return
# if no tool name given, use caller's source file name as tool name
if Line == None:
Line = "..."
else:
TemplateDict = {
"tool" : ToolName,
"file" : File,
"line" : Line,
"msg" : Message,
}
if File != None:
else:
if ExtraData != None:
# Raise an execption if indicated
if _WarningAsError == True:
raise FatalError(WARNING_AS_ERROR)
## Log INFO message
## Log ERROR message
#
# Once an error messages is logged, the tool's execution will be broken by raising
# an execption. If you don't want to break the execution later, you can give
# "RaiseError" with "False" value.
#
# @param ToolName The name of the tool. If not given, the name of caller
# method will be used.
# @param ErrorCode The error code
# @param Message Warning information
# @param File The name of file which caused the error.
# @param Line The line number in the "File" which caused the warning.
# @param ExtraData More information associated with "Message"
# @param RaiseError Raise an exception to break the tool's executuion if
# it's True. This is the default behavior.
#
def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None, RaiseError=IsRaiseError):
if Line == None:
Line = "..."
else:
if Message == None:
if ErrorCode in gErrorMessage:
else:
if ExtraData == None:
ExtraData = ""
TemplateDict = {
"tool" : _ToolName,
"file" : File,
"line" : Line,
"errorcode" : ErrorCode,
"msg" : Message,
"extra" : ExtraData
}
if File != None:
else:
# VBox - begin
# VBox - endi
if RaiseError:
raise FatalError(ErrorCode)
# Log information which should be always put out
# VBox - begin
## Get caller info
# @return String with caller name, file and line number.
# @param iFrame The frame number of the caller to get.
if oFrame is None:
try:
raise Exception();
except:
while iFrame > 1:
if oFrame is not None:
if oFrame is not None:
return None;
## @Get a simple stack trace.
# @return simple stack trace (string).
# @param iFrame The frame to start with.
# @param cMaxFrames The maximum number of frames to dump.
sStack = 'Stack:\n'
for i in range(cMaxFrames):
if sCaller is None:
break;
return sStack;
# VBox - end
## Initialize log system
def Initialize():
#
# Since we use different format to log different levels of message into different
# place (stdout or stderr), we have to use different "Logger" objects to do this.
#
# For DEBUG level (All DEBUG_0~9 are applicable)
# For VERBOSE, INFO, WARN level
# For ERROR level
## Set log level
#
# @param Level One of log level in _LogLevel
if Level not in _LogLevels:
## Get current log level
def GetLevel():
return _InfoLogger.getEffectiveLevel()
## Raise up warning as error
def SetWarningAsError():
global _WarningAsError
## Specify a file to store the log message as well as put on console
#
# @param LogFile The file path used to store the log message
#
if __name__ == '__main__':
pass