Skip to content

Commit

Permalink
compatible fix for sanic 19.12+ #49
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Bui committed Jul 15, 2020
1 parent 0cec8e1 commit 29fc74b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## 1.2.0 - 2020-07-14
- fix #49

## 1.2.0 - 2020-04-10
- fix #45
- fix #46
Expand Down
13 changes: 8 additions & 5 deletions json_logging/framework/sanic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def config(self, app):

@app.middleware('request')
def before_request(request):
request['request_info'] = json_logging.RequestInfo(request)
request.ctx.request_info = json_logging.RequestInfo(request)

@app.middleware('response')
def after_request(request, response):
request_info = request['request_info']
request_info = request.ctx.request_info
request_info.update_response_status(response)
self.request_logger.info("", extra={'request_info': request_info, 'type': 'request'})

Expand Down Expand Up @@ -93,11 +93,14 @@ def get_http_header(self, request, header_name, default=None):
return request.headers.get(header_name)
return default

def set_correlation_id(self, request_, value):
request_['correlation_id'] = value
def set_correlation_id(self, request, value):
request.ctx.correlation_id = value

def get_correlation_id_in_request_context(self, request):
return request.get('correlation_id')
try:
return request.ctx.correlation_id
except AttributeError:
return None

def get_protocol(self, request):
return json_logging.EMPTY_VALUE
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="json-logging",
version='1.2.0',
version='1.2.1',
packages=find_packages(exclude=['contrib', 'docs', 'tests*', 'example', 'dist', 'build']),
license='Apache License 2.0',
description="JSON Python Logging",
Expand Down

0 comments on commit 29fc74b

Please sign in to comment.