## @file\r
# This file implements the log mechanism for Python tools.\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
# which accompanies this distribution. The full text of the license may be found at\r
#\r
\r
## Import modules\r
+from __future__ import absolute_import\r
import Common.LongFilePathOs as os, sys, logging\r
import traceback\r
-from BuildToolError import *\r
+from .BuildToolError import *\r
\r
## Log level constants\r
DEBUG_0 = 1\r
WARN = 30\r
QUIET = 40\r
ERROR = 50\r
+SILENT = 99\r
\r
IsRaiseError = True\r
\r
_ToolName = os.path.basename(sys.argv[0])\r
\r
# For validation purpose\r
-_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]\r
+_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5,\r
+ DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO,\r
+ ERROR, QUIET, SILENT]\r
\r
# For DEBUG level (All DEBUG_0~9 are applicable)\r
_DebugLogger = logging.getLogger("tool_debug")\r
"msg" : Message,\r
}\r
\r
- if ExtraData != None:\r
+ if ExtraData is not None:\r
LogText = _DebugMessageTemplate % TemplateDict + "\n %s" % ExtraData\r
else:\r
LogText = _DebugMessageTemplate % TemplateDict\r
return\r
\r
# if no tool name given, use caller's source file name as tool name\r
- if ToolName == None or ToolName == "":\r
+ if ToolName is None or ToolName == "":\r
ToolName = os.path.basename(traceback.extract_stack()[-2][0])\r
\r
- if Line == None:\r
+ if Line is None:\r
Line = "..."\r
else:\r
Line = "%d" % Line\r
"msg" : Message,\r
}\r
\r
- if File != None:\r
+ if File is not None:\r
LogText = _WarningMessageTemplate % TemplateDict\r
else:\r
LogText = _WarningMessageTemplateWithoutFile % TemplateDict\r
\r
- if ExtraData != None:\r
+ if ExtraData is not None:\r
LogText += "\n %s" % ExtraData\r
\r
_InfoLogger.log(WARN, LogText)\r
\r
- # Raise an execption if indicated\r
+ # Raise an exception if indicated\r
if _WarningAsError == True:\r
raise FatalError(WARNING_AS_ERROR)\r
\r
## Log ERROR message\r
#\r
# Once an error messages is logged, the tool's execution will be broken by raising\r
-# an execption. If you don't want to break the execution later, you can give\r
+# an exception. If you don't want to break the execution later, you can give\r
# "RaiseError" with "False" value.\r
#\r
# @param ToolName The name of the tool. If not given, the name of caller\r
# @param File The name of file which caused the error.\r
# @param Line The line number in the "File" which caused the warning.\r
# @param ExtraData More information associated with "Message"\r
-# @param RaiseError Raise an exception to break the tool's executuion if\r
+# @param RaiseError Raise an exception to break the tool's execution if\r
# it's True. This is the default behavior.\r
#\r
def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None, RaiseError=IsRaiseError):\r
- if Line == None:\r
+ if Line is None:\r
Line = "..."\r
else:\r
Line = "%d" % Line\r
\r
- if Message == None:\r
+ if Message is None:\r
if ErrorCode in gErrorMessage:\r
Message = gErrorMessage[ErrorCode]\r
else:\r
Message = gErrorMessage[UNKNOWN_ERROR]\r
\r
- if ExtraData == None:\r
+ if ExtraData is None:\r
ExtraData = ""\r
\r
TemplateDict = {\r
"extra" : ExtraData\r
}\r
\r
- if File != None:\r
+ if File is not None:\r
LogText = _ErrorMessageTemplate % TemplateDict\r
else:\r
LogText = _ErrorMessageTemplateWithoutFile % TemplateDict\r
\r
_ErrorLogger.log(ERROR, LogText)\r
- if RaiseError:\r
+\r
+ if RaiseError and IsRaiseError:\r
raise FatalError(ErrorCode)\r
\r
# Log information which should be always put out\r
_InfoLogger.setLevel(Level)\r
_ErrorLogger.setLevel(Level)\r
\r
+def InitializeForUnitTest():\r
+ Initialize()\r
+ SetLevel(SILENT)\r
+\r
## Get current log level\r
def GetLevel():\r
return _InfoLogger.getEffectiveLevel()\r