From a9a9bd25632235911058779dec017f330c234164 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 17 Dec 2021 01:45:18 +0900 Subject: [PATCH] Fix #9979: Error level messages were displayed as warning messages --- CHANGES | 1 + sphinx/util/logging.py | 9 ++++++++- tests/test_util_logging.py | 10 +++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 9d57f8349ab..63f7416a29f 100644 --- a/CHANGES +++ b/CHANGES @@ -51,6 +51,7 @@ Bugs fixed * #9940: LaTeX: Multi-function declaration in Python domain has cramped vertical spacing in latexpdf output * #9390: texinfo: Do not emit labels inside footnotes +* #9979: Error level messages were displayed as warning messages Testing -------- diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index ae8fc25cfb5..ef36e3cf103 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -111,7 +111,14 @@ class SphinxInfoLogRecord(SphinxLogRecord): class SphinxWarningLogRecord(SphinxLogRecord): """Warning log record class supporting location""" - prefix = 'WARNING: ' + @property + def prefix(self) -> str: # type: ignore + if self.levelno >= logging.CRITICAL: + return 'CRITICAL: ' + elif self.levelno >= logging.ERROR: + return 'ERROR: ' + else: + return 'WARNING: ' class SphinxLoggerAdapter(logging.LoggerAdapter): diff --git a/tests/test_util_logging.py b/tests/test_util_logging.py index b8a0ca2e200..057d38546d8 100644 --- a/tests/test_util_logging.py +++ b/tests/test_util_logging.py @@ -41,9 +41,9 @@ def test_info_and_warning(app, status, warning): assert 'message1' not in warning.getvalue() assert 'message2' not in warning.getvalue() - assert 'message3' in warning.getvalue() - assert 'message4' in warning.getvalue() - assert 'message5' in warning.getvalue() + assert 'WARNING: message3' in warning.getvalue() + assert 'CRITICAL: message4' in warning.getvalue() + assert 'ERROR: message5' in warning.getvalue() def test_Exception(app, status, warning): @@ -305,8 +305,8 @@ def test_colored_logs(app, status, warning): assert 'message2\n' in status.getvalue() # not colored assert 'message3\n' in status.getvalue() # not colored assert colorize('red', 'WARNING: message4') in warning.getvalue() - assert 'WARNING: message5\n' in warning.getvalue() # not colored - assert colorize('darkred', 'WARNING: message6') in warning.getvalue() + assert 'CRITICAL: message5\n' in warning.getvalue() # not colored + assert colorize('darkred', 'ERROR: message6') in warning.getvalue() # color specification logger.debug('message7', color='white')