Skip to content

Commit

Permalink
fix: change logging to include a log key
Browse files Browse the repository at this point in the history
  • Loading branch information
brett-vendia committed Jan 8, 2021
1 parent daa656b commit 542d473
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ function proxy ({
log,
respondWithErrors
}) {
log.debug('Calling proxy', { event, context, resolutionMode, eventSource })
log.debug('SERVERLESS_EXPRESS:PROXY', {
event,
context,
resolutionMode,
eventSource,
binaryMimeTypes,
respondWithErrors
})
setCurrentLambdaInvoke({ event, context })
return new Promise((resolve, reject) => {
const promise = {
Expand Down
13 changes: 8 additions & 5 deletions src/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ function forwardResponse ({
eventResponseMapperFn,
log
}) {
log.debug('Forwarding response from application to API Gateway... HTTP response:', { headers: response.headers, statusCode: response.statusCode })
log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:HTTP_RESPONSE', {
headers: response.headers,
statusCode: response.statusCode
})
const statusCode = response.statusCode
const headers = Response.headers(response)
const contentType = getContentType({
contentTypeHeader: headers['content-type']
})
log.debug('contentType', { contentType })
log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:CONTENT_TYPE', { contentType })
const isBase64Encoded = isContentTypeBinaryMimeType({
contentType,
binaryMimeTypes
Expand All @@ -38,7 +41,7 @@ function forwardResponse ({
isBase64Encoded
})

log.debug('Forwarding response from application to API Gateway... API Gateway response:', { successResponse })
log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:API_GATEWAY_RESPONSE', { successResponse })
resolver.succeed({
response: successResponse
})
Expand All @@ -51,7 +54,7 @@ function forwardLibraryErrorResponseToApiGateway ({
respondWithErrors,
eventResponseMapperFn
}) {
log.error('serverless-express error: ', error)
log.error('SERVERLESS_EXPRESS:FORWARD_LIBRARY_ERROR_RESPONSE_TO_API_GATEWAY:ERROR', error)

const body = respondWithErrors ? error.stack : ''
const errorResponse = eventResponseMapperFn({
Expand All @@ -77,7 +80,7 @@ async function forwardRequestToNodeServer ({
}) {
const eventResponseMapperFn = eventFns.response
const requestValues = eventFns.getRequestValues({ event })
log.debug('Forwarding request to application...', { requestValues })
log.debug('SERVERLESS_EXPRESS:REQUEST_VALUES', { requestValues })
const response = await framework.sendRequest({ app, requestValues })
forwardResponse({
binaryMimeTypes,
Expand Down

0 comments on commit 542d473

Please sign in to comment.