mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Only configure logging inside the context
This commit is contained in:
parent
bdc58cc33f
commit
e4f0b4c1b7
3 changed files with 14 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue