Skip to content

Commit

Permalink
logger: use custom handler to propagare logging exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Jun 23, 2019
1 parent c0a06d2 commit 6f05e77
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import colorama


class LoggingException(Exception):
def __init__(self, record):
msg = "failed to log {}".format(str(record))
super(LoggingException, self).__init__(msg)


class ExcludeErrorsFilter(logging.Filter):
def filter(self, record):
return record.levelno < logging.ERROR
Expand Down Expand Up @@ -149,6 +155,12 @@ def _progress_aware(self):
progress.clearln()


class LoggerHandler(logging.StreamHandler):
def handleError(self, record):
super(LoggerHandler, self).handleError(record)
raise LoggingException(record)


def setup(level=logging.INFO):
colorama.init()

Expand All @@ -159,14 +171,14 @@ def setup(level=logging.INFO):
"formatters": {"color": {"()": ColorFormatter}},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"class": "dvc.logger.LoggerHandler",
"level": "DEBUG",
"formatter": "color",
"stream": "ext://sys.stdout",
"filters": ["exclude_errors"],
},
"console_errors": {
"class": "logging.StreamHandler",
"class": "dvc.logger.LoggerHandler",
"level": "ERROR",
"formatter": "color",
"stream": "ext://sys.stderr",
Expand Down

0 comments on commit 6f05e77

Please sign in to comment.