Skip to content

Commit

Permalink
fix: remove winston dependency and add basic logger
Browse files Browse the repository at this point in the history
  • Loading branch information
brett-vendia committed Jan 6, 2021
1 parent 60cb8e1 commit 5bd6c2c
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 296 deletions.
41 changes: 13 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,6 @@ ExpressApi:
BinaryMediaTypes: ['application/json', 'image/*']
```
### loggerConfig
Provide additional [Winston logger](https://www.npmjs.com/package/winston) configuration. For example, you could add a new transport to emit any errors to a separate CloudWatch Metric or Log Group. `loggerConfig` will be shallow-merged into the default configuration.

```js
// Default:
{
level: 'warning',
format: format.combine(
format.colorize(),
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.errors({ stack: true }),
format.json()
),
transports: [
new transports.Console()
]
}
```

### resolutionMode (default: `'PROMISE'`)
Lambda supports three methods to end the execution and return a result: context, callback, and promise. By default, serverless-express uses promise resolution, but you can specify 'CONTEXT' or 'CALLBACK' if you need to change this. If you specify 'CALLBACK', then `context.callbackWaitsForEmptyEventLoop = false` is also set for you.
Expand Down Expand Up @@ -130,15 +108,22 @@ configure({
})
```

### logger
### log

Provide a `logger` object with `debug` and `error` methods to override the default [Winston logger](https://www.npmjs.com/package/winston). For example, you could have any error logs also emit to a separate CloudWatch Metric or Log Group, though in most cases you should be able to simply provide `loggerConfig` with additional log transports.
Provide a custom `log` object with `info`, `debug` and `error` methods. For example, you could override the default with a [Winston log](https://www.npmjs.com/package/winston) instance.

```js
{
logger: {
debug: (message, additional) => {/*...*/},
error: (message, additional) => {/*...*/}
log: {
info (message, additional) {
console.info(message, additional)
},
debug (message, additional) {
console.debug(message, additional)
},
error (message, additional) {
console.error(message, additional)
}
}
}
```
Expand Down Expand Up @@ -192,7 +177,7 @@ app.get('/', (req, res) => {
- For apps that may not see traffic for several minutes at a time, you could see [cold starts](https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/)
- Cannot use native libraries (aka [Addons](https://nodejs.org/api/addons.html)) unless you package your app on an EC2 machine running Amazon Linux
- Stateless only
- API Gateway has a timeout of 30 seconds, and Lambda has a maximum execution time of 15 minutes.
- API Gateway has a timeout of 29 seconds, and Lambda has a maximum execution time of 15 minutes.

## Loadtesting

Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const fs = require('fs')
const vendiaServerlessExpress = require('../index')
const vendiaServerlessExpress = require('../src/index')
const apiGatewayEvent = require('../examples/basic-starter-api-gateway-v1/api-gateway-event.json')
const app = require('../examples/basic-starter-api-gateway-v1/src/app')

Expand Down
17 changes: 9 additions & 8 deletions __tests__/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const eventSources = require('../src/event-sources')
const ServerlessRequest = require('../src/request')
const ServerlessResponse = require('../src/response')
const expressFramework = require('../src/frameworks/express')
const logger = {
const log = {
info: () => null,
debug: () => null,
error: () => null
}
Expand Down Expand Up @@ -134,7 +135,7 @@ describe('forwardLibraryErrorResponseToApiGateway', () => {
serverlessExpressTransport.forwardLibraryErrorResponseToApiGateway({
error: new Error('ERROR'),
resolver: contextResolver,
logger,
log,
eventResponseMapperFn: apiGatewayEventSource.response
})
}
Expand All @@ -155,7 +156,7 @@ describe('forwardLibraryErrorResponseToApiGateway', () => {
serverlessExpressTransport.forwardLibraryErrorResponseToApiGateway({
error: new Error('There was an error...'),
resolver: contextResolver,
logger,
log,
respondWithErrors: true,
eventResponseMapperFn: apiGatewayEventSource.response
})
Expand Down Expand Up @@ -195,7 +196,7 @@ describe.skip('forwardResponse: content-type encoding', () => {
response,
resolver: contextResolver,
eventResponseMapperFn: apiGatewayEventSource.response,
logger
log
})
}
).then(successResponse => expect(successResponse).toEqual({
Expand All @@ -220,7 +221,7 @@ describe.skip('forwardResponse: content-type encoding', () => {
response,
resolver: contextResolver,
eventResponseMapperFn: apiGatewayEventSource.response,
logger
log
})
}
).then(successResponse => expect(successResponse).toEqual({
Expand All @@ -244,7 +245,7 @@ describe.skip('forwardResponse: content-type encoding', () => {
response,
resolver: contextResolver,
eventResponseMapperFn: apiGatewayEventSource.response,
logger
log
})
}
).then(successResponse => expect(successResponse).toEqual({
Expand All @@ -268,7 +269,7 @@ describe.skip('forwardResponse: content-type encoding', () => {
response,
resolver: contextResolver,
eventResponseMapperFn: apiGatewayEventSource.response,
logger
log
})
}
).then(successResponse => expect(successResponse).toEqual({
Expand All @@ -292,7 +293,7 @@ describe.skip('forwardResponse: content-type encoding', () => {
response,
resolver: contextResolver,
eventResponseMapperFn: apiGatewayEventSource.response,
logger
log
})
}
).then(successResponse => expect(successResponse).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-starter-api-gateway-v1/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const compression = require('compression')
const { getCurrentLambdaInvoke } = require(process.env.NODE_ENV === 'test' ? '../../../index' : '@vendia/serverless-express')
const { getCurrentLambdaInvoke } = require(process.env.NODE_ENV === 'test' ? '../../../src/index' : '@vendia/serverless-express')
const app = express()
const router = express.Router()

Expand Down
6 changes: 1 addition & 5 deletions examples/basic-starter-api-gateway-v1/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const binaryMimeTypes = [
]
const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
})
exports.handler = se.handler
2 changes: 1 addition & 1 deletion examples/basic-starter-api-gateway-v2/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const compression = require('compression')
const { getCurrentLambdaInvoke } = require(process.env.NODE_ENV === 'test' ? '../../../index' : '@vendia/serverless-express')
const { getCurrentLambdaInvoke } = require(process.env.NODE_ENV === 'test' ? '../../../src/index' : '@vendia/serverless-express')
const app = express()
const router = express.Router()

Expand Down
6 changes: 1 addition & 5 deletions examples/basic-starter-api-gateway-v2/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const binaryMimeTypes = [
]
const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
})
exports.handler = se.handler
6 changes: 1 addition & 5 deletions examples/basic-starter-hapi/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const binaryMimeTypes = [
]
const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
})
exports.handler = se.handler
6 changes: 1 addition & 5 deletions examples/basic-starter-koa/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const binaryMimeTypes = [
]
const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
})
exports.handler = se.handler
3 changes: 0 additions & 3 deletions examples/custom-mapper-dynamodb/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const se = serverlessExpress.configure({
eventFns: {
request: mapDynamoDbEventToHttpRequest,
response: mapResponseToDynamoDb
},
loggerConfig: {
level: 'debug'
}
})

Expand Down
6 changes: 1 addition & 5 deletions examples/lambda-edge/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ const binaryMimeTypes = [

const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
})
exports.handler = se.handler
6 changes: 1 addition & 5 deletions examples/sails/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ exports.handler = async (event, context, callback) => {
const app = await appPromise;
const se = serverlessExpress.configure({
app,
binaryMimeTypes,
respondWithErrors: true,
loggerConfig: {
level: 'debug'
}
binaryMimeTypes
});

return se.proxy({ event, context, callback });
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

Loading

0 comments on commit 5bd6c2c

Please sign in to comment.