mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Only configure logging inside the context
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
from pre_commit import color
|
||||
@@ -34,6 +35,12 @@ class LoggingHandler(logging.Handler):
|
||||
)
|
||||
|
||||
|
||||
def add_logging_handler(*args, **kwargs):
|
||||
logger.addHandler(LoggingHandler(*args, **kwargs))
|
||||
@contextlib.contextmanager
|
||||
def logging_handler(*args, **kwargs):
|
||||
handler = LoggingHandler(*args, **kwargs)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
logger.removeHandler(handler)
|
||||
|
||||
Reference in New Issue
Block a user