aio-libs/aiohttp-remotes

Access logger does not use correct remote address

Fogapod opened this issue · 3 comments

Not sure if this is a aiohttp-remotes issue, but it seems like default access logger uses old request without updated remote address.
I deploy my aiohttp server with XForwardedRelaxed helper behind nginx and assign X-Forwarded-For header: proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; I can confirm that request was updated properly by printing it from route, but access logs always point to localhost.
What can be done to fix access logger output?

The access log is configurable: http://docs.aiohttp.org/en/stable/logging.html#format-specification
Would you add %{X-Forwarded-For }i format spec to the list of default output?

For some reason, I get keyerror in this case. I inspected headers provided by logger, there are only User-Agent and Referer: 'request_header': {'Referer': '-', 'User-Agent': 'Mozilla/5.0 (Linux; Android 8.1.0; Lenovo TB-8704X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'}
Code I used to get this:

import logging

access_log = logging.getLogger('aiohttp.access')

class TestHandler(logging.StreamHandler):
    def emit(self, record):
        print(record.__dict__)

access_log.addHandler(TestHandler())

However I can get propper headers in my middlewares and route handlers.
Am I doing something wrong?

I used logger in a wrong way. Closing issue