From ed167d661c052cf4df2942e79960930de984a676 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 26 Mar 2017 18:53:08 +0900 Subject: [PATCH] Fix app.messagelog does not filled after moving to logging module --- sphinx/application.py | 1 + sphinx/util/logging.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/sphinx/application.py b/sphinx/application.py index e735b8530..5481e2963 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -153,6 +153,7 @@ class Sphinx(object): self._translators = {} # type: Dict[unicode, nodes.GenericNodeVisitor] # keep last few messages for traceback + # This will be filled by sphinx.util.logging.LastMessagesWriter self.messagelog = deque(maxlen=10) # type: deque # say hello to the world diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index 0699503ea..ec6637fa0 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -406,6 +406,17 @@ class SafeEncodingWriter(object): self.stream.flush() +class LastMessagesWriter(object): + """Stream writer which memories last 10 messages to save trackback""" + def __init__(self, app, stream): + # type: (IO) -> None + self.app = app + + def write(self, data): + # type: (unicode) -> None + self.app.messagelog.append(data) + + def setup(app, status, warning): # type: (Sphinx, IO, IO) -> None """Setup root logger for Sphinx""" @@ -427,5 +438,12 @@ def setup(app, status, warning): warning_handler.addFilter(WarningLogRecordTranslator(app)) warning_handler.setLevel(logging.WARNING) warning_handler.setFormatter(ColorizeFormatter()) + + messagelog_handler = logging.StreamHandler(LastMessagesWriter(app, status)) + messagelog_handler.addFilter(InfoFilter()) + messagelog_handler.setLevel(VERBOSITY_MAP[app.verbosity]) + messagelog_handler.setFormatter(ColorizeFormatter()) + logger.addHandler(info_handler) logger.addHandler(warning_handler) + logger.addHandler(messagelog_handler)