Skip to content

Commit

Permalink
Closes #9733: Fix for logging handler flushing warnings in the middle…
Browse files Browse the repository at this point in the history
… of the build

Summary:
My project was mysteriously dropping warnings (see #9733 for detailed repro) and I realized that it's becaues it imports libraries like airflow or mlflow that set up loggers automatically when they are imported. This causes this handler to flush even though shouldFlush is set to always return False. A simple workaround is to override flush to be a no-op.

Test Plan: Repeat repro steps from #9733 - project now always includes warnings
  • Loading branch information
gibsondan committed Oct 25, 2021
1 parent cf38356 commit b1c0d1f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sphinx/util/logging.py
Expand Up @@ -171,6 +171,11 @@ def __init__(self) -> None:
def shouldFlush(self, record: logging.LogRecord) -> bool:
return False # never flush

def flush(self) -> None:
# suppress any flushes triggered by importing packages that flush
# all handlers at initialization time
pass

def flushTo(self, logger: logging.Logger) -> None:
self.acquire()
try:
Expand Down

0 comments on commit b1c0d1f

Please sign in to comment.