human
Complete the below
def _logging(original):

    ''''Decorate a method which implements an API endpoint to add Eliot-based
    logging.
    Calls to the decorated function will be in a L{REQUEST} action.  If the
    decorated function raises an exception then the exception will be logged
    and a token which identifies that log event sent in the response.'
    '''

Give me a the Python code you requested?
assistant
#Here is the Python code you requested.
    @wraps(original)
    def logger(self, request, **routeArguments):
        logger = _get_logger(self)
        action = REQUEST(logger, request_path=request.path, method=request.method)
        incidentIdentifier = action.serialize_task_id()
        with action.context():
            d = DeferredContext(original(self, request, **routeArguments))
        def failure(reason):
            if reason.check(BadRequest):
                code = reason.value.code
                result = reason.value.result
            else:
                writeFailure(reason, logger, LOG_SYSTEM)
                code = INTERNAL_SERVER_ERROR
                result = incidentIdentifier
            request.setResponseCode(code)
            request.responseHeaders.setRawHeaders('content-type', ['application/json'])
            return dumps(result)
        d.addErrback(failure)
        d.addActionFinish()
        return d.result
    return logger