## @file
# This file implements the log mechanism for Python tools.
#
# Copyright (c) 2011, 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.
#
'''
Logger
'''
## Import modules
#
# Log level constants
#
#
# Tool name
#
#
# For validation purpose
#
#
# For DEBUG level (All DEBUG_0~9 are applicable)
#
datefmt="%H:%M:%S")
#
# For VERBOSE, INFO, WARN level
#
#
# For ERROR level
#
#
#
('\n\n%(tool)s...\n%(file)s(%(line)s): error %(errorcode)04X: %(msg)s\n\t%(extra)s')
'\n\n%(tool)s...\n : error %(errorcode)04X: %(msg)s\n\t%(extra)s'
#
# Log INFO message
#
#Info = _INFO_LOGGER.info
#
# Log information which should be always put out
#
## 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
#
raise FatalError(WARNING_AS_ERROR)
## 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.
#
if ToolName:
pass
if Line == None:
Line = "..."
else:
if Message == None:
if ErrorCode in gERROR_MESSAGE:
else:
if ExtraData == None:
ExtraData = ""
TemplateDict = {
"tool" : _TOOL_NAME,
"file" : File,
"line" : Line,
"errorcode" : ErrorCode,
"msg" : Message,
"extra" : ExtraData
}
if File != None:
else:
if not SUPRESS_ERROR:
if RaiseError:
raise FatalError(ErrorCode)
## 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 _LOG_LEVELS:
Info("Not supported log level (%d). Use default level instead." % \
## Get current log level
#
def GetLevel():
return _INFO_LOGGER.getEffectiveLevel()
## Raise up warning as error
#
def SetWarningAsError():
## 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
#