Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-03-17 19:33:20 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-03-17 19:35:30 +0300
commit2f33b9376b8cf2c4ca6bd00ccf248038e2afbdea (patch)
treeea5069d56178a7b521f66bc0288ef81b6103fc5c /sphinx/util/logging.py
parent385f7ed40ef843db94ec33ad377aa87d63f27a27 (diff)
Add suppress_logging()
As a helper for C/C++ domain, this adds suppress_logging(). It works as a context manager and suppresses all loggings during the context temporarily.
Diffstat (limited to 'sphinx/util/logging.py')
-rw-r--r--sphinx/util/logging.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py
index fb2ec2900..a2dee807d 100644
--- a/sphinx/util/logging.py
+++ b/sphinx/util/logging.py
@@ -220,16 +220,15 @@ def pending_warnings() -> Generator[logging.Handler, None, None]:
@contextmanager
-def pending_logging() -> Generator[MemoryHandler, None, None]:
- """Contextmanager to pend logging all logs temporary.
+def suppress_logging() -> Generator[MemoryHandler, None, None]:
+ """Contextmanager to suppress logging all logs temporary.
For example::
- >>> with pending_logging():
- >>> logger.warning('Warning message!') # not flushed yet
+ >>> with suppress_logging():
+ >>> logger.warning('Warning message!') # suppressed
>>> some_long_process()
>>>
- Warning message! # the warning is flushed here
"""
logger = logging.getLogger(NAMESPACE)
memhandler = MemoryHandler()
@@ -248,6 +247,24 @@ def pending_logging() -> Generator[MemoryHandler, None, None]:
for handler in handlers:
logger.addHandler(handler)
+
+@contextmanager
+def pending_logging() -> Generator[MemoryHandler, None, None]:
+ """Contextmanager to pend logging all logs temporary.
+
+ For example::
+
+ >>> with pending_logging():
+ >>> logger.warning('Warning message!') # not flushed yet
+ >>> some_long_process()
+ >>>
+ Warning message! # the warning is flushed here
+ """
+ logger = logging.getLogger(NAMESPACE)
+ try:
+ with suppress_logging() as memhandler:
+ yield memhandler
+ finally:
memhandler.flushTo(logger)