Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9979: Error level messages were displayed as warning messages #9982

Merged
merged 1 commit into from Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
--------
Expand Down
9 changes: 8 additions & 1 deletion sphinx/util/logging.py
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_util_logging.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down