prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error integrating with Channels if 'lifespan' is not specified in router
  I'm not entirely sure if I should be posting this here or on `channels`.
  
  I'm using v0.3.12 which I believe has already introduced the new `lifespan` protocol defined in asgiref. But this causes an error with `channels`' router
  
  ```bash
  Traceback (most recent call last):
     File "/usr/local/lib/python3.6/site-packages/uvicorn/lifespan.py", line 29, in run
       await self.asgi(self.receive, self.send)
     File "/usr/local/lib/python3.6/site-packages/uvicorn/middleware/message_logger.py", line 51, in __call__
       inner = self.app(self.scope)
     File "/usr/local/lib/python3.6/site-packages/channels/routing.py", line 58, in __call__
       raise ValueError("No application configured for scope type %r" % scope["type"])
  ValueError: No application configured for scope type 'lifespan'
  ```
  
  My `routing.py` file looks like this:
  
  ```python
  application = ProtocolTypeRouter({
      # Empty for now (http->django views is added by default)
      'websocket': JWTWebsocketMiddleware(
          URLRouter(urlpatterns)
      )
  })
  ```
  
  **EDIT**: Sorry my workaround wasn't actually working as you'll need at least one `path` in the `URLRouter`, so I've removed it.
  
  To temporarily get around this, I had to downgrade to `v0.3.9`.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `uvicorn/middleware/message_logger.py`
  Content:
  ```
  1 import logging
  2 
  3 PLACEHOLDER_FORMAT = {
  4     'body': '<{length} bytes>',
  5     'bytes': '<{length} bytes>',
  6     'text': '<{length} chars>',
  7     'headers': '<...>',
  8 }
  9 
  10 
  11 def message_with_placeholders(message):
  12     """
  13     Return an ASGI message, with any body-type content omitted and replaced
  14     with a placeholder.
  15     """
  16     new_message = message.copy()
  17     for attr in PLACEHOLDER_FORMAT.keys():
  18         if message.get(attr) is not None:
  19             content = message[attr]
  20             placeholder = PLACEHOLDER_FORMAT[attr].format(length=len(content))
  21             new_message[attr] = placeholder
  22     return new_message
  23 
  24 
  25 class MessageLoggerMiddleware:
  26     def __init__(self, app):
  27         self.task_counter = 0
  28         self.app = app
  29         self.logger = logging.getLogger("uvicorn")
  30 
  31     def __call__(self, scope):
  32         self.task_counter += 1
  33         return MessageLoggerResponder(scope, self.app, self.logger, self.task_counter)
  34 
  35 
  36 class MessageLoggerResponder:
  37     def __init__(self, scope, app, logger, task_counter):
  38         self.scope = scope
  39         self.app = app
  40         self.logger = logger
  41         self.task_counter = task_counter
  42         self.client_addr = scope.get('client')
  43 
  44     async def __call__(self, receive, send):
  45         self._receive = receive
  46         self._send = send
  47         logged_scope = message_with_placeholders(self.scope)
  48         log_text = '%s - ASGI [%d] Started %s'
  49         self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)
  50         try:
  51             inner = self.app(self.scope)
  52             await inner(self.receive, self.send)
  53         except:
  54             log_text = '%s - ASGI [%d] Raised exception'
  55             self.logger.debug(log_text, self.client_addr, self.task_counter)
  56             raise
  57         else:
  58             log_text = '%s - ASGI [%d] Completed'
  59             self.logger.debug(log_text, self.client_addr, self.task_counter)
  60 
  61     async def receive(self):
  62         message = await self._receive()
  63         logged_message = message_with_placeholders(message)
  64         log_text = '%s - ASGI [%d] Sent %s'
  65         self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)
  66         return message
  67 
  68     async def send(self, message):
  69         logged_message = message_with_placeholders(message)
  70         log_text = '%s - ASGI [%d] Received %s'
  71         self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)
  72         await self._send(message)
  73
  ```
  --- 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/uvicorn/middleware/message_logger.py b/uvicorn/middleware/message_logger.py
  --- a/uvicorn/middleware/message_logger.py
  +++ b/uvicorn/middleware/message_logger.py
  @@ -36,20 +36,27 @@
   class MessageLoggerResponder:
       def __init__(self, scope, app, logger, task_counter):
           self.scope = scope
  -        self.app = app
           self.logger = logger
           self.task_counter = task_counter
           self.client_addr = scope.get('client')
   
  +        logged_scope = message_with_placeholders(scope)
  +        log_text = '%s - ASGI [%d] Initialized %s'
  +        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)
  +        try:
  +            self.inner = app(scope)
  +        except:
  +            log_text = '%s - ASGI [%d] Raised exception'
  +            self.logger.debug(log_text, self.client_addr, self.task_counter)
  +            raise
  +
       async def __call__(self, receive, send):
           self._receive = receive
           self._send = send
  -        logged_scope = message_with_placeholders(self.scope)
  -        log_text = '%s - ASGI [%d] Started %s'
  -        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)
  +        log_text = '%s - ASGI [%d] Started task'
  +        self.logger.debug(log_text, self.client_addr, self.task_counter)
           try:
  -            inner = self.app(self.scope)
  -            await inner(self.receive, self.send)
  +            await self.inner(self.receive, self.send)
           except:
               log_text = '%s - ASGI [%d] Raised exception'
               self.logger.debug(log_text, self.client_addr, self.task_counter)
  
verification_info: {"golden_diff": "diff --git a/uvicorn/middleware/message_logger.py b/uvicorn/middleware/message_logger.py\n--- a/uvicorn/middleware/message_logger.py\n+++ b/uvicorn/middleware/message_logger.py\n@@ -36,20 +36,27 @@\n class MessageLoggerResponder:\n     def __init__(self, scope, app, logger, task_counter):\n         self.scope = scope\n-        self.app = app\n         self.logger = logger\n         self.task_counter = task_counter\n         self.client_addr = scope.get('client')\n \n+        logged_scope = message_with_placeholders(scope)\n+        log_text = '%s - ASGI [%d] Initialized %s'\n+        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)\n+        try:\n+            self.inner = app(scope)\n+        except:\n+            log_text = '%s - ASGI [%d] Raised exception'\n+            self.logger.debug(log_text, self.client_addr, self.task_counter)\n+            raise\n+\n     async def __call__(self, receive, send):\n         self._receive = receive\n         self._send = send\n-        logged_scope = message_with_placeholders(self.scope)\n-        log_text = '%s - ASGI [%d] Started %s'\n-        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)\n+        log_text = '%s - ASGI [%d] Started task'\n+        self.logger.debug(log_text, self.client_addr, self.task_counter)\n         try:\n-            inner = self.app(self.scope)\n-            await inner(self.receive, self.send)\n+            await self.inner(self.receive, self.send)\n         except:\n             log_text = '%s - ASGI [%d] Raised exception'\n             self.logger.debug(log_text, self.client_addr, self.task_counter)\n", "issue": "Error integrating with Channels if 'lifespan' is not specified in router\nI'm not entirely sure if I should be posting this here or on `channels`.\r\n\r\nI'm using v0.3.12 which I believe has already introduced the new `lifespan` protocol defined in asgiref. But this causes an error with `channels`' router\r\n\r\n```bash\r\nTraceback (most recent call last):\r\n   File \"/usr/local/lib/python3.6/site-packages/uvicorn/lifespan.py\", line 29, in run\r\n     await self.asgi(self.receive, self.send)\r\n   File \"/usr/local/lib/python3.6/site-packages/uvicorn/middleware/message_logger.py\", line 51, in __call__\r\n     inner = self.app(self.scope)\r\n   File \"/usr/local/lib/python3.6/site-packages/channels/routing.py\", line 58, in __call__\r\n     raise ValueError(\"No application configured for scope type %r\" % scope[\"type\"])\r\nValueError: No application configured for scope type 'lifespan'\r\n```\r\n\r\nMy `routing.py` file looks like this:\r\n\r\n```python\r\napplication = ProtocolTypeRouter({\r\n    # Empty for now (http->django views is added by default)\r\n    'websocket': JWTWebsocketMiddleware(\r\n        URLRouter(urlpatterns)\r\n    )\r\n})\r\n```\r\n\r\n**EDIT**: Sorry my workaround wasn't actually working as you'll need at least one `path` in the `URLRouter`, so I've removed it.\r\n\r\nTo temporarily get around this, I had to downgrade to `v0.3.9`.\n", "before_files": [{"content": "import logging\n\nPLACEHOLDER_FORMAT = {\n    'body': '<{length} bytes>',\n    'bytes': '<{length} bytes>',\n    'text': '<{length} chars>',\n    'headers': '<...>',\n}\n\n\ndef message_with_placeholders(message):\n    \"\"\"\n    Return an ASGI message, with any body-type content omitted and replaced\n    with a placeholder.\n    \"\"\"\n    new_message = message.copy()\n    for attr in PLACEHOLDER_FORMAT.keys():\n        if message.get(attr) is not None:\n            content = message[attr]\n            placeholder = PLACEHOLDER_FORMAT[attr].format(length=len(content))\n            new_message[attr] = placeholder\n    return new_message\n\n\nclass MessageLoggerMiddleware:\n    def __init__(self, app):\n        self.task_counter = 0\n        self.app = app\n        self.logger = logging.getLogger(\"uvicorn\")\n\n    def __call__(self, scope):\n        self.task_counter += 1\n        return MessageLoggerResponder(scope, self.app, self.logger, self.task_counter)\n\n\nclass MessageLoggerResponder:\n    def __init__(self, scope, app, logger, task_counter):\n        self.scope = scope\n        self.app = app\n        self.logger = logger\n        self.task_counter = task_counter\n        self.client_addr = scope.get('client')\n\n    async def __call__(self, receive, send):\n        self._receive = receive\n        self._send = send\n        logged_scope = message_with_placeholders(self.scope)\n        log_text = '%s - ASGI [%d] Started %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)\n        try:\n            inner = self.app(self.scope)\n            await inner(self.receive, self.send)\n        except:\n            log_text = '%s - ASGI [%d] Raised exception'\n            self.logger.debug(log_text, self.client_addr, self.task_counter)\n            raise\n        else:\n            log_text = '%s - ASGI [%d] Completed'\n            self.logger.debug(log_text, self.client_addr, self.task_counter)\n\n    async def receive(self):\n        message = await self._receive()\n        logged_message = message_with_placeholders(message)\n        log_text = '%s - ASGI [%d] Sent %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)\n        return message\n\n    async def send(self, message):\n        logged_message = message_with_placeholders(message)\n        log_text = '%s - ASGI [%d] Received %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)\n        await self._send(message)\n", "path": "uvicorn/middleware/message_logger.py"}], "after_files": [{"content": "import logging\n\nPLACEHOLDER_FORMAT = {\n    'body': '<{length} bytes>',\n    'bytes': '<{length} bytes>',\n    'text': '<{length} chars>',\n    'headers': '<...>',\n}\n\n\ndef message_with_placeholders(message):\n    \"\"\"\n    Return an ASGI message, with any body-type content omitted and replaced\n    with a placeholder.\n    \"\"\"\n    new_message = message.copy()\n    for attr in PLACEHOLDER_FORMAT.keys():\n        if message.get(attr) is not None:\n            content = message[attr]\n            placeholder = PLACEHOLDER_FORMAT[attr].format(length=len(content))\n            new_message[attr] = placeholder\n    return new_message\n\n\nclass MessageLoggerMiddleware:\n    def __init__(self, app):\n        self.task_counter = 0\n        self.app = app\n        self.logger = logging.getLogger(\"uvicorn\")\n\n    def __call__(self, scope):\n        self.task_counter += 1\n        return MessageLoggerResponder(scope, self.app, self.logger, self.task_counter)\n\n\nclass MessageLoggerResponder:\n    def __init__(self, scope, app, logger, task_counter):\n        self.scope = scope\n        self.logger = logger\n        self.task_counter = task_counter\n        self.client_addr = scope.get('client')\n\n        logged_scope = message_with_placeholders(scope)\n        log_text = '%s - ASGI [%d] Initialized %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_scope)\n        try:\n            self.inner = app(scope)\n        except:\n            log_text = '%s - ASGI [%d] Raised exception'\n            self.logger.debug(log_text, self.client_addr, self.task_counter)\n            raise\n\n    async def __call__(self, receive, send):\n        self._receive = receive\n        self._send = send\n        log_text = '%s - ASGI [%d] Started task'\n        self.logger.debug(log_text, self.client_addr, self.task_counter)\n        try:\n            await self.inner(self.receive, self.send)\n        except:\n            log_text = '%s - ASGI [%d] Raised exception'\n            self.logger.debug(log_text, self.client_addr, self.task_counter)\n            raise\n        else:\n            log_text = '%s - ASGI [%d] Completed'\n            self.logger.debug(log_text, self.client_addr, self.task_counter)\n\n    async def receive(self):\n        message = await self._receive()\n        logged_message = message_with_placeholders(message)\n        log_text = '%s - ASGI [%d] Sent %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)\n        return message\n\n    async def send(self, message):\n        logged_message = message_with_placeholders(message)\n        log_text = '%s - ASGI [%d] Received %s'\n        self.logger.debug(log_text, self.client_addr, self.task_counter, logged_message)\n        await self._send(message)\n", "path": "uvicorn/middleware/message_logger.py"}]}