Skip to content

Conversation

FraBle
Copy link

@FraBle FraBle commented Mar 8, 2018

This pull request adds support for Falcon by:

  • adding a Falcon middleware sap.cf_logging.falcon_logging.LoggingMiddleware
  • implementing Context, RequestReader, ResponseReader as adapter to Falcon
  • implementing init to initialize CF Logging with Falcon connection

Tests have been added and the Readme has been updated with an example.

Since Falcon does not provide a global context like Flask (with flask.g), it leverages the req object for context. A log() method gets attached to the req object in the middleware to avoid the necessity to provide extra with the request object for logging (like in the sanic implementation).

@gvachkov gvachkov self-requested a review March 9, 2018 09:40
Copy link
Contributor

@gvachkov gvachkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Frank,

Thanks a lot for your contribution, the change looks nice! Please check my comments, there are few small things I would prefer to be changed.

best regards,
Georgi

This is needed in order to get the *correlation_id* generated at the beginning of the request or
fetched from the HTTP headers.

Falcon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add to the Features section the support for Falcon, I would suggest creating a bulleted list containing the supported frameworks.

class FalconRequestReader(RequestReader):
def get_remote_user(self, request):
remote_user = defaults.UNKNOWN
http_auth = request.get_header('Authorization')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to parse auth headers into the logging lib, rather to support the most common authentication frameworks and the way they provide user info. I would suggest to read the user from the request context as expected to be set by falcon-auth authentication layer.

class LoggingMiddleware:

def __init__(self, logger='cf.falcon.logger'):
self.logger = logger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name logger suggest an object, but this is a name, can you name it like logger_name for better readability?

@gvachkov
Copy link
Contributor

The Falcon support has been added via: #15.
Closing this PR.

@gvachkov gvachkov closed this May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants