BaseTools: Add LogAgent to support multiple process Autogen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1875 AutoGen processes race the logfile. To resolve this issue, this patch create a LogAgent thread in main process to write the log content to console or file, Other process will send the log content to the LogAgent. Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Bob Feng <bob.c.feng@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -10,6 +10,7 @@ from __future__ import absolute_import
|
||||
import Common.LongFilePathOs as os, sys, logging
|
||||
import traceback
|
||||
from .BuildToolError import *
|
||||
import logging.handlers
|
||||
|
||||
## Log level constants
|
||||
DEBUG_0 = 1
|
||||
@ -199,6 +200,41 @@ def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=Non
|
||||
# Log information which should be always put out
|
||||
quiet = _ErrorLogger.error
|
||||
|
||||
## Initialize log system
|
||||
def LogClientInitialize(log_q):
|
||||
#
|
||||
# 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)
|
||||
_DebugLogger.setLevel(INFO)
|
||||
_DebugChannel = logging.handlers.QueueHandler(log_q)
|
||||
_DebugChannel.setFormatter(_DebugFormatter)
|
||||
_DebugLogger.addHandler(_DebugChannel)
|
||||
|
||||
# For VERBOSE, INFO, WARN level
|
||||
_InfoLogger.setLevel(INFO)
|
||||
_InfoChannel = logging.handlers.QueueHandler(log_q)
|
||||
_InfoChannel.setFormatter(_InfoFormatter)
|
||||
_InfoLogger.addHandler(_InfoChannel)
|
||||
|
||||
# For ERROR level
|
||||
_ErrorLogger.setLevel(INFO)
|
||||
_ErrorCh = logging.handlers.QueueHandler(log_q)
|
||||
_ErrorCh.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_ErrorCh)
|
||||
|
||||
## Set log level
|
||||
#
|
||||
# @param Level One of log level in _LogLevel
|
||||
def SetLevel(Level):
|
||||
if Level not in _LogLevels:
|
||||
info("Not supported log level (%d). Use default level instead." % Level)
|
||||
Level = INFO
|
||||
_DebugLogger.setLevel(Level)
|
||||
_InfoLogger.setLevel(Level)
|
||||
_ErrorLogger.setLevel(Level)
|
||||
|
||||
## Initialize log system
|
||||
def Initialize():
|
||||
#
|
||||
@ -223,17 +259,6 @@ def Initialize():
|
||||
_ErrorCh.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_ErrorCh)
|
||||
|
||||
## Set log level
|
||||
#
|
||||
# @param Level One of log level in _LogLevel
|
||||
def SetLevel(Level):
|
||||
if Level not in _LogLevels:
|
||||
info("Not supported log level (%d). Use default level instead." % Level)
|
||||
Level = INFO
|
||||
_DebugLogger.setLevel(Level)
|
||||
_InfoLogger.setLevel(Level)
|
||||
_ErrorLogger.setLevel(Level)
|
||||
|
||||
def InitializeForUnitTest():
|
||||
Initialize()
|
||||
SetLevel(SILENT)
|
||||
|
Reference in New Issue
Block a user