Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsgi: move write access log info to own function #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

wsgi: move write access log info to own function #382

wants to merge 1 commit into from

Conversation

scarchik
Copy link

Modify wsgi.py:
move write access log info to own function for better way to override and modify access log.

Due to necessity to write this info log in json format and add to log additional information from headers.

@codecov-io
Copy link

Current coverage is 59% (diff: 100%)

Merging #382 into master will increase coverage by 5%

@@             master       #382   diff @@
==========================================
  Files            78         76      -2   
  Lines          8947       7079   -1868   
  Methods           0          0           
  Messages          0          0           
  Branches       1539       1108    -431   
==========================================
- Hits           4871       4237    -634   
+ Misses         3757       2566   -1191   
+ Partials        319        276     -43   

Powered by Codecov. Last update 0fdb115...e9f26c1

@temoto
Copy link
Member

temoto commented Jan 26, 2017

Can you show how this is used?

@temoto
Copy link
Member

temoto commented Jan 26, 2017

It seems overriden function doesn't get a lot of useful information and has to resort to copying code.

@scarchik
Copy link
Author

scarchik commented Jan 26, 2017

Actually I want override this function instead of override handle_one_response.
I use python-json-logger to report logs in json format to GrayLog and I need add to this log request_id from headers.

My code will be like this:

 class HttpProtocolWithRequestID(wsgi.HttpProtocol):

    def write_access_log(self, **kwargs):
        client_host, client_port = self.get_client_address()
        extra = {
                    'client_ip': self.get_client_ip(),
                    'client_port': self.client_address[1],
                    'date_time': self.log_date_time_string(),
                    'request_line': self.requestline,
                    'status_code': status_code[0],
                    'body_length': length[0],
                    'wall_seconds': finish - start,
                    'request_id': _get_request_id()
        }

        self.server.log.info(self.server.log_format % extra, extra=extra)

Log example:
{"asctime": "2017-01-26 16:08:50,110", "msecs": 110.32581329345703, "levelname": "INFO", "module": "eventlet_http_protocol", "lineno": 184, "args": [], "msg": "10.10.11.29 - - [26/Jan/2017 16:08:50] "PATCH /admin/user/3 HTTP/1.1" 500 279 0.067530", "request_id": "admin.user_update.patch.482d89a5-a13f-4822-8cf6-a580c5f4e489", "client_ip": "10.10.11.29", "client_port": 61258, "request_line": "PATCH /admin/wallet/3 HTTP/1.1", "status_code": "500", "date_time": "26/Jan/2017 16:08:50", "wall_seconds": 0.06752991676330566, "body_length": 279}

From eventlet versions 0.19 and 0.20.1 function handle_one_response had changed that why I also need change my code. This change help resolve this problem in future.

@temoto
Copy link
Member

temoto commented Jan 27, 2017

Okay, thanks, I understand problem and use case now. I'll modify your patch to avoid copying code like get_client_address() call and let you review.

Ping and angry reminders are welcome.

@scarchik
Copy link
Author

Ok. Any changes is up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants