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)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from pre_commit.commands.sample_config import sample_config
|
|||
from pre_commit.commands.try_repo import try_repo
|
||||
from pre_commit.error_handler import error_handler
|
||||
from pre_commit.error_handler import FatalError
|
||||
from pre_commit.logging_handler import add_logging_handler
|
||||
from pre_commit.logging_handler import logging_handler
|
||||
from pre_commit.store import Store
|
||||
from pre_commit.util import CalledProcessError
|
||||
|
||||
|
|
@ -248,9 +248,7 @@ def main(argv=None):
|
|||
elif args.command == 'help':
|
||||
parser.parse_args(['--help'])
|
||||
|
||||
with error_handler():
|
||||
add_logging_handler(args.color)
|
||||
|
||||
with error_handler(), logging_handler(args.color):
|
||||
_adjust_args_and_chdir(args)
|
||||
|
||||
store = Store()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue