prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  logger: still ignoring the context of the progress bar
  version: `0.40.0+6408b5`
  
  When trying to push to an SSH with the `ask_password` option set to `True`:
  ```
  # [############                  ] 40% Collecting informationEnter a private key passphrase or a password for host 'localhost' port '22' user 'mroutis':
  ```
  
  This behavior should be handle at: https://github.com/iterative/dvc/blob/6408b58b8daddc297467453bcd130c07b09cd46b/dvc/logger.py#L134-L140
  
  It should be tested under `tests/unit/test_logger.py`
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `dvc/logger.py`
  Content:
  ```
  1 """Manages logging configuration for dvc repo."""
  2 
  3 from __future__ import unicode_literals
  4 
  5 from dvc.utils.compat import str, StringIO
  6 
  7 import logging
  8 import logging.handlers
  9 import logging.config
  10 import colorama
  11 
  12 
  13 class ExcludeErrorsFilter(logging.Filter):
  14     def filter(self, record):
  15         return record.levelno < logging.ERROR
  16 
  17 
  18 class ColorFormatter(logging.Formatter):
  19     """Enable color support when logging to a terminal that supports it.
  20 
  21     Color support on Windows versions that do not support ANSI color codes is
  22     enabled by use of the colorama__ library.
  23     See the colorama documentation for details.
  24 
  25     __ https://pypi.python.org/pypi/colorama
  26 
  27     For records containing `exc_info`, it will use a custom `_walk_exc` to
  28     retrieve the whole tracebak.
  29     """
  30 
  31     color_code = {
  32         "DEBUG": colorama.Fore.BLUE,
  33         "INFO": "",
  34         "WARNING": colorama.Fore.YELLOW,
  35         "ERROR": colorama.Fore.RED,
  36         "CRITICAL": colorama.Fore.RED,
  37     }
  38 
  39     footer = (
  40         "{yellow}Having any troubles?{nc}."
  41         " Hit us up at {blue}https://dvc.org/support{nc},"
  42         " we are always happy to help!"
  43     ).format(
  44         blue=colorama.Fore.BLUE,
  45         nc=colorama.Fore.RESET,
  46         yellow=colorama.Fore.YELLOW,
  47     )
  48 
  49     def format(self, record):
  50         if record.levelname == "INFO":
  51             return record.msg
  52 
  53         if record.levelname == "ERROR" or record.levelname == "CRITICAL":
  54             exception, stack_trace = self._parse_exc(record.exc_info)
  55 
  56             return (
  57                 "{color}{levelname}{nc}: {description}"
  58                 "{stack_trace}\n"
  59                 "\n"
  60                 "{footer}"
  61             ).format(
  62                 color=self.color_code.get(record.levelname, ""),
  63                 nc=colorama.Fore.RESET,
  64                 levelname=record.levelname,
  65                 description=self._description(record.msg, exception),
  66                 msg=record.msg,
  67                 stack_trace=stack_trace,
  68                 footer=self.footer,
  69             )
  70 
  71         return "{color}{levelname}{nc}: {msg}".format(
  72             color=self.color_code.get(record.levelname, ""),
  73             nc=colorama.Fore.RESET,
  74             levelname=record.levelname,
  75             msg=record.msg,
  76         )
  77 
  78     def _description(self, message, exception):
  79         description = ""
  80 
  81         if exception and message:
  82             description = "{message} - {exception}"
  83         elif exception:
  84             description = "{exception}"
  85         elif message:
  86             description = "{message}"
  87 
  88         return description.format(message=message, exception=exception)
  89 
  90     def _walk_exc(self, exc_info):
  91         import traceback
  92 
  93         buffer = StringIO()
  94 
  95         traceback.print_exception(*exc_info, file=buffer)
  96 
  97         exc = exc_info[1]
  98         tb = buffer.getvalue()
  99 
  100         exc_list = [str(exc)]
  101         tb_list = [tb]
  102 
  103         # NOTE: parsing chained exceptions. See dvc/exceptions.py for more info
  104         while hasattr(exc, "cause") and exc.cause:
  105             exc_list.append(str(exc.cause))
  106             if hasattr(exc, "cause_tb") and exc.cause_tb:
  107                 tb_list.insert(0, str(exc.cause_tb))
  108             exc = exc.cause
  109 
  110         return exc_list, tb_list
  111 
  112     def _parse_exc(self, exc_info):
  113         if not exc_info:
  114             return (None, "")
  115 
  116         exc_list, tb_list = self._walk_exc(exc_info)
  117 
  118         exception = ": ".join(exc_list)
  119 
  120         if logging.getLogger("dvc").getEffectiveLevel() == logging.DEBUG:
  121             stack_trace = (
  122                 "\n" "{red}{line}{nc}\n" "{stack_trace}" "{red}{line}{nc}"
  123             ).format(
  124                 red=colorama.Fore.RED,
  125                 nc=colorama.Fore.RESET,
  126                 line="-" * 60,
  127                 stack_trace="\n".join(tb_list),
  128             )
  129         else:
  130             stack_trace = ""
  131 
  132         return (exception, stack_trace)
  133 
  134     def _progress_aware(self):
  135         """Add a new line if progress bar hasn't finished"""
  136         from dvc.progress import progress
  137 
  138         if not progress.is_finished:
  139             progress._print()
  140         progress.clearln()
  141 
  142 
  143 def setup(level=logging.INFO):
  144     colorama.init()
  145 
  146     logging.config.dictConfig(
  147         {
  148             "version": 1,
  149             "filters": {"exclude_errors": {"()": ExcludeErrorsFilter}},
  150             "formatters": {"color": {"()": ColorFormatter}},
  151             "handlers": {
  152                 "console": {
  153                     "class": "logging.StreamHandler",
  154                     "level": "DEBUG",
  155                     "formatter": "color",
  156                     "stream": "ext://sys.stdout",
  157                     "filters": ["exclude_errors"],
  158                 },
  159                 "console_errors": {
  160                     "class": "logging.StreamHandler",
  161                     "level": "ERROR",
  162                     "formatter": "color",
  163                     "stream": "ext://sys.stderr",
  164                 },
  165             },
  166             "loggers": {
  167                 "dvc": {
  168                     "level": level,
  169                     "handlers": ["console", "console_errors"],
  170                 }
  171             },
  172         }
  173     )
  174
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/dvc/logger.py b/dvc/logger.py
  --- a/dvc/logger.py
  +++ b/dvc/logger.py
  @@ -47,6 +47,9 @@
       )
   
       def format(self, record):
  +        if self._is_visible(record):
  +            self._progress_aware()
  +
           if record.levelname == "INFO":
               return record.msg
   
  @@ -75,6 +78,12 @@
               msg=record.msg,
           )
   
  +    def _current_level(self):
  +        return logging.getLogger("dvc").getEffectiveLevel()
  +
  +    def _is_visible(self, record):
  +        return record.levelno >= self._current_level()
  +
       def _description(self, message, exception):
           description = ""
   
  @@ -117,7 +126,7 @@
   
           exception = ": ".join(exc_list)
   
  -        if logging.getLogger("dvc").getEffectiveLevel() == logging.DEBUG:
  +        if self._current_level() == logging.DEBUG:
               stack_trace = (
                   "\n" "{red}{line}{nc}\n" "{stack_trace}" "{red}{line}{nc}"
               ).format(
  
verification_info: {"golden_diff": "diff --git a/dvc/logger.py b/dvc/logger.py\n--- a/dvc/logger.py\n+++ b/dvc/logger.py\n@@ -47,6 +47,9 @@\n     )\n \n     def format(self, record):\n+        if self._is_visible(record):\n+            self._progress_aware()\n+\n         if record.levelname == \"INFO\":\n             return record.msg\n \n@@ -75,6 +78,12 @@\n             msg=record.msg,\n         )\n \n+    def _current_level(self):\n+        return logging.getLogger(\"dvc\").getEffectiveLevel()\n+\n+    def _is_visible(self, record):\n+        return record.levelno >= self._current_level()\n+\n     def _description(self, message, exception):\n         description = \"\"\n \n@@ -117,7 +126,7 @@\n \n         exception = \": \".join(exc_list)\n \n-        if logging.getLogger(\"dvc\").getEffectiveLevel() == logging.DEBUG:\n+        if self._current_level() == logging.DEBUG:\n             stack_trace = (\n                 \"\\n\" \"{red}{line}{nc}\\n\" \"{stack_trace}\" \"{red}{line}{nc}\"\n             ).format(\n", "issue": "logger: still ignoring the context of the progress bar\nversion: `0.40.0+6408b5`\r\n\r\nWhen trying to push to an SSH with the `ask_password` option set to `True`:\r\n```\r\n# [############                  ] 40% Collecting informationEnter a private key passphrase or a password for host 'localhost' port '22' user 'mroutis':\r\n```\r\n\r\nThis behavior should be handle at: https://github.com/iterative/dvc/blob/6408b58b8daddc297467453bcd130c07b09cd46b/dvc/logger.py#L134-L140\r\n\r\nIt should be tested under `tests/unit/test_logger.py`\n", "before_files": [{"content": "\"\"\"Manages logging configuration for dvc repo.\"\"\"\n\nfrom __future__ import unicode_literals\n\nfrom dvc.utils.compat import str, StringIO\n\nimport logging\nimport logging.handlers\nimport logging.config\nimport colorama\n\n\nclass ExcludeErrorsFilter(logging.Filter):\n    def filter(self, record):\n        return record.levelno < logging.ERROR\n\n\nclass ColorFormatter(logging.Formatter):\n    \"\"\"Enable color support when logging to a terminal that supports it.\n\n    Color support on Windows versions that do not support ANSI color codes is\n    enabled by use of the colorama__ library.\n    See the colorama documentation for details.\n\n    __ https://pypi.python.org/pypi/colorama\n\n    For records containing `exc_info`, it will use a custom `_walk_exc` to\n    retrieve the whole tracebak.\n    \"\"\"\n\n    color_code = {\n        \"DEBUG\": colorama.Fore.BLUE,\n        \"INFO\": \"\",\n        \"WARNING\": colorama.Fore.YELLOW,\n        \"ERROR\": colorama.Fore.RED,\n        \"CRITICAL\": colorama.Fore.RED,\n    }\n\n    footer = (\n        \"{yellow}Having any troubles?{nc}.\"\n        \" Hit us up at {blue}https://dvc.org/support{nc},\"\n        \" we are always happy to help!\"\n    ).format(\n        blue=colorama.Fore.BLUE,\n        nc=colorama.Fore.RESET,\n        yellow=colorama.Fore.YELLOW,\n    )\n\n    def format(self, record):\n        if record.levelname == \"INFO\":\n            return record.msg\n\n        if record.levelname == \"ERROR\" or record.levelname == \"CRITICAL\":\n            exception, stack_trace = self._parse_exc(record.exc_info)\n\n            return (\n                \"{color}{levelname}{nc}: {description}\"\n                \"{stack_trace}\\n\"\n                \"\\n\"\n                \"{footer}\"\n            ).format(\n                color=self.color_code.get(record.levelname, \"\"),\n                nc=colorama.Fore.RESET,\n                levelname=record.levelname,\n                description=self._description(record.msg, exception),\n                msg=record.msg,\n                stack_trace=stack_trace,\n                footer=self.footer,\n            )\n\n        return \"{color}{levelname}{nc}: {msg}\".format(\n            color=self.color_code.get(record.levelname, \"\"),\n            nc=colorama.Fore.RESET,\n            levelname=record.levelname,\n            msg=record.msg,\n        )\n\n    def _description(self, message, exception):\n        description = \"\"\n\n        if exception and message:\n            description = \"{message} - {exception}\"\n        elif exception:\n            description = \"{exception}\"\n        elif message:\n            description = \"{message}\"\n\n        return description.format(message=message, exception=exception)\n\n    def _walk_exc(self, exc_info):\n        import traceback\n\n        buffer = StringIO()\n\n        traceback.print_exception(*exc_info, file=buffer)\n\n        exc = exc_info[1]\n        tb = buffer.getvalue()\n\n        exc_list = [str(exc)]\n        tb_list = [tb]\n\n        # NOTE: parsing chained exceptions. See dvc/exceptions.py for more info\n        while hasattr(exc, \"cause\") and exc.cause:\n            exc_list.append(str(exc.cause))\n            if hasattr(exc, \"cause_tb\") and exc.cause_tb:\n                tb_list.insert(0, str(exc.cause_tb))\n            exc = exc.cause\n\n        return exc_list, tb_list\n\n    def _parse_exc(self, exc_info):\n        if not exc_info:\n            return (None, \"\")\n\n        exc_list, tb_list = self._walk_exc(exc_info)\n\n        exception = \": \".join(exc_list)\n\n        if logging.getLogger(\"dvc\").getEffectiveLevel() == logging.DEBUG:\n            stack_trace = (\n                \"\\n\" \"{red}{line}{nc}\\n\" \"{stack_trace}\" \"{red}{line}{nc}\"\n            ).format(\n                red=colorama.Fore.RED,\n                nc=colorama.Fore.RESET,\n                line=\"-\" * 60,\n                stack_trace=\"\\n\".join(tb_list),\n            )\n        else:\n            stack_trace = \"\"\n\n        return (exception, stack_trace)\n\n    def _progress_aware(self):\n        \"\"\"Add a new line if progress bar hasn't finished\"\"\"\n        from dvc.progress import progress\n\n        if not progress.is_finished:\n            progress._print()\n        progress.clearln()\n\n\ndef setup(level=logging.INFO):\n    colorama.init()\n\n    logging.config.dictConfig(\n        {\n            \"version\": 1,\n            \"filters\": {\"exclude_errors\": {\"()\": ExcludeErrorsFilter}},\n            \"formatters\": {\"color\": {\"()\": ColorFormatter}},\n            \"handlers\": {\n                \"console\": {\n                    \"class\": \"logging.StreamHandler\",\n                    \"level\": \"DEBUG\",\n                    \"formatter\": \"color\",\n                    \"stream\": \"ext://sys.stdout\",\n                    \"filters\": [\"exclude_errors\"],\n                },\n                \"console_errors\": {\n                    \"class\": \"logging.StreamHandler\",\n                    \"level\": \"ERROR\",\n                    \"formatter\": \"color\",\n                    \"stream\": \"ext://sys.stderr\",\n                },\n            },\n            \"loggers\": {\n                \"dvc\": {\n                    \"level\": level,\n                    \"handlers\": [\"console\", \"console_errors\"],\n                }\n            },\n        }\n    )\n", "path": "dvc/logger.py"}], "after_files": [{"content": "\"\"\"Manages logging configuration for dvc repo.\"\"\"\n\nfrom __future__ import unicode_literals\n\nfrom dvc.utils.compat import str, StringIO\n\nimport logging\nimport logging.handlers\nimport logging.config\nimport colorama\n\n\nclass ExcludeErrorsFilter(logging.Filter):\n    def filter(self, record):\n        return record.levelno < logging.ERROR\n\n\nclass ColorFormatter(logging.Formatter):\n    \"\"\"Enable color support when logging to a terminal that supports it.\n\n    Color support on Windows versions that do not support ANSI color codes is\n    enabled by use of the colorama__ library.\n    See the colorama documentation for details.\n\n    __ https://pypi.python.org/pypi/colorama\n\n    For records containing `exc_info`, it will use a custom `_walk_exc` to\n    retrieve the whole tracebak.\n    \"\"\"\n\n    color_code = {\n        \"DEBUG\": colorama.Fore.BLUE,\n        \"INFO\": \"\",\n        \"WARNING\": colorama.Fore.YELLOW,\n        \"ERROR\": colorama.Fore.RED,\n        \"CRITICAL\": colorama.Fore.RED,\n    }\n\n    footer = (\n        \"{yellow}Having any troubles?{nc}.\"\n        \" Hit us up at {blue}https://dvc.org/support{nc},\"\n        \" we are always happy to help!\"\n    ).format(\n        blue=colorama.Fore.BLUE,\n        nc=colorama.Fore.RESET,\n        yellow=colorama.Fore.YELLOW,\n    )\n\n    def format(self, record):\n        if self._is_visible(record):\n            self._progress_aware()\n\n        if record.levelname == \"INFO\":\n            return record.msg\n\n        if record.levelname == \"ERROR\" or record.levelname == \"CRITICAL\":\n            exception, stack_trace = self._parse_exc(record.exc_info)\n\n            return (\n                \"{color}{levelname}{nc}: {description}\"\n                \"{stack_trace}\\n\"\n                \"\\n\"\n                \"{footer}\"\n            ).format(\n                color=self.color_code.get(record.levelname, \"\"),\n                nc=colorama.Fore.RESET,\n                levelname=record.levelname,\n                description=self._description(record.msg, exception),\n                msg=record.msg,\n                stack_trace=stack_trace,\n                footer=self.footer,\n            )\n\n        return \"{color}{levelname}{nc}: {msg}\".format(\n            color=self.color_code.get(record.levelname, \"\"),\n            nc=colorama.Fore.RESET,\n            levelname=record.levelname,\n            msg=record.msg,\n        )\n\n    def _current_level(self):\n        return logging.getLogger(\"dvc\").getEffectiveLevel()\n\n    def _is_visible(self, record):\n        return record.levelno >= self._current_level()\n\n    def _description(self, message, exception):\n        description = \"\"\n\n        if exception and message:\n            description = \"{message} - {exception}\"\n        elif exception:\n            description = \"{exception}\"\n        elif message:\n            description = \"{message}\"\n\n        return description.format(message=message, exception=exception)\n\n    def _walk_exc(self, exc_info):\n        import traceback\n\n        buffer = StringIO()\n\n        traceback.print_exception(*exc_info, file=buffer)\n\n        exc = exc_info[1]\n        tb = buffer.getvalue()\n\n        exc_list = [str(exc)]\n        tb_list = [tb]\n\n        # NOTE: parsing chained exceptions. See dvc/exceptions.py for more info\n        while hasattr(exc, \"cause\") and exc.cause:\n            exc_list.append(str(exc.cause))\n            if hasattr(exc, \"cause_tb\") and exc.cause_tb:\n                tb_list.insert(0, str(exc.cause_tb))\n            exc = exc.cause\n\n        return exc_list, tb_list\n\n    def _parse_exc(self, exc_info):\n        if not exc_info:\n            return (None, \"\")\n\n        exc_list, tb_list = self._walk_exc(exc_info)\n\n        exception = \": \".join(exc_list)\n\n        if self._current_level() == logging.DEBUG:\n            stack_trace = (\n                \"\\n\" \"{red}{line}{nc}\\n\" \"{stack_trace}\" \"{red}{line}{nc}\"\n            ).format(\n                red=colorama.Fore.RED,\n                nc=colorama.Fore.RESET,\n                line=\"-\" * 60,\n                stack_trace=\"\\n\".join(tb_list),\n            )\n        else:\n            stack_trace = \"\"\n\n        return (exception, stack_trace)\n\n    def _progress_aware(self):\n        \"\"\"Add a new line if progress bar hasn't finished\"\"\"\n        from dvc.progress import progress\n\n        if not progress.is_finished:\n            progress._print()\n        progress.clearln()\n\n\ndef setup(level=logging.INFO):\n    colorama.init()\n\n    logging.config.dictConfig(\n        {\n            \"version\": 1,\n            \"filters\": {\"exclude_errors\": {\"()\": ExcludeErrorsFilter}},\n            \"formatters\": {\"color\": {\"()\": ColorFormatter}},\n            \"handlers\": {\n                \"console\": {\n                    \"class\": \"logging.StreamHandler\",\n                    \"level\": \"DEBUG\",\n                    \"formatter\": \"color\",\n                    \"stream\": \"ext://sys.stdout\",\n                    \"filters\": [\"exclude_errors\"],\n                },\n                \"console_errors\": {\n                    \"class\": \"logging.StreamHandler\",\n                    \"level\": \"ERROR\",\n                    \"formatter\": \"color\",\n                    \"stream\": \"ext://sys.stderr\",\n                },\n            },\n            \"loggers\": {\n                \"dvc\": {\n                    \"level\": level,\n                    \"handlers\": [\"console\", \"console_errors\"],\n                }\n            },\n        }\n    )\n", "path": "dvc/logger.py"}]}