From: Valeriy Savchenko Date: Tue, 9 Jun 2020 09:33:56 +0000 (+0300) Subject: [analyzer] SATest: Use logger in single-threaded mode as well X-Git-Tag: llvmorg-12-init~1979 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=495fd64041909d07fe9ba57cbf4274a9db1a9ea3;p=platform%2Fupstream%2Fllvm.git [analyzer] SATest: Use logger in single-threaded mode as well Summary: It generalizes the way the output looks across any -jN. Additionally it solves the buffering problems. Differential Revision: https://reviews.llvm.org/D81601 --- diff --git a/clang/utils/analyzer/SATestBuild.py b/clang/utils/analyzer/SATestBuild.py index af32f40..7d33763 100644 --- a/clang/utils/analyzer/SATestBuild.py +++ b/clang/utils/analyzer/SATestBuild.py @@ -70,9 +70,27 @@ from typing import Dict, IO, List, NamedTuple, Optional, TYPE_CHECKING # Helper functions. ############################################################################### +class StreamToLogger: + def __init__(self, logger: logging.Logger, + log_level: int = logging.INFO): + self.logger = logger + self.log_level = log_level + + def write(self, message: str): + # Rstrip in order not to write an extra newline. + self.logger.log(self.log_level, message.rstrip()) + + def flush(self): + pass + + def fileno(self) -> int: + return 0 + + +Logger = logging.getLogger("main") LOCAL = threading.local() -LOCAL.stdout = sys.stdout -LOCAL.stderr = sys.stderr +LOCAL.stdout = StreamToLogger(Logger, logging.INFO) +LOCAL.stderr = StreamToLogger(Logger, logging.ERROR) def stderr(message: str): @@ -164,23 +182,6 @@ CHECKERS = ",".join([ VERBOSE = 0 -class StreamToLogger: - def __init__(self, logger: logging.Logger, - log_level: int = logging.INFO): - self.logger = logger - self.log_level = log_level - - def write(self, message: str): - # Rstrip in order not to write an extra newline. - self.logger.log(self.log_level, message.rstrip()) - - def flush(self): - pass - - def fileno(self) -> int: - return 0 - - ############################################################################### # Test harness logic. ###############################################################################