Skip to content

Commit

Permalink
close #88 by adding interface to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Dec 26, 2018
1 parent 96687cb commit 7d6c169
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ The `REQUEST` object contains a parsed and normalized request from API Gateway.
- `app`: A reference to an instance of the app
- `version`: The version set at initialization
- `id`: The awsRequestId from the Lambda `context`
- `interface`: The interface being used to access Lambda (either `apigateway` or `alb`)
- `interface`: The interface being used to access Lambda (`apigateway`,`alb`, or `edge`)
- `params`: Dynamic path parameters parsed from the path (see [path parameters](#path-parameters))
- `method`: The HTTP method of the request
- `path`: The path passed in by the request including the `base` and any `prefix` assigned to routes
Expand Down Expand Up @@ -850,6 +850,7 @@ Logs are generated using Lambda API's standard JSON format. The log format can b
"remaining": 2000, // remaining milliseconds until function timeout
"function": "my-function-v1", // function name
"memory": 2048, // allocated function memory
"int": "apigateway", // interface used to access the Lambda function
"sample": true // is generated during sampling request?
}
```
Expand Down
1 change: 1 addition & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ exports.config = (config,levels) => {
method: req.method,
[messageKey]: msg,
timer: timer(req._start),
int: req.interface,
sample: req._sample ? true : undefined
},
serializers.main(req),
Expand Down
17 changes: 17 additions & 0 deletions test/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[4]).to.have.property('coldStart')
expect(_log[4]).to.have.property('statusCode')
Expand Down Expand Up @@ -278,6 +279,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[4]).to.have.property('coldStart')
expect(_log[4]).to.have.property('statusCode')
Expand Down Expand Up @@ -331,6 +333,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[5]).to.have.property('coldStart')
expect(_log[5]).to.have.property('statusCode')
Expand Down Expand Up @@ -384,6 +387,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('statusCode')
Expand Down Expand Up @@ -422,6 +426,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('statusCode')
Expand Down Expand Up @@ -458,6 +463,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('statusCode')
Expand Down Expand Up @@ -495,6 +501,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('statusCode')
Expand Down Expand Up @@ -533,6 +540,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('statusCode')
Expand Down Expand Up @@ -577,6 +585,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('coldStart')
expect(_log[0]).to.have.property('path')
expect(_log[0]).to.have.property('ip')
Expand All @@ -593,6 +602,7 @@ describe('Logging Tests:', function() {
expect(_log[1]).to.have.property('remaining')
expect(_log[1]).to.have.property('function')
expect(_log[1]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
expect(_log[1]).to.have.property('coldStart')
expect(_log[1]).to.have.property('path')
expect(_log[1]).to.have.property('ip')
Expand Down Expand Up @@ -627,6 +637,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
// these should NOT exist
expect(_log[0]).to.not.have.property('coldStart')
expect(_log[0]).to.not.have.property('statusCode')
Expand Down Expand Up @@ -664,6 +675,7 @@ describe('Logging Tests:', function() {
expect(_log[0].context).to.have.property('remaining')
expect(_log[0].context).to.have.property('function')
expect(_log[0].context).to.have.property('memory')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('custom')
expect(_log[0].custom).to.have.property('customMsg')
// access log
Expand Down Expand Up @@ -702,6 +714,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('path')
expect(_log[0]).to.have.property('ip')
expect(_log[0]).to.have.property('ua')
Expand Down Expand Up @@ -752,6 +765,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('timer')
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('int')
// access log
expect(_log[3]).to.have.property('time')
expect(_log[3]).to.have.property('id')
Expand Down Expand Up @@ -793,6 +807,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('msg')
expect(_log[0]).to.have.property('timer')
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('TEST_CUSTOM')
expect(_log[0]).to.have.property('TEST_CONTEXT')
Expand Down Expand Up @@ -839,6 +854,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('msg')
expect(_log[0]).to.have.property('timer')
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('custom')
// access log
Expand Down Expand Up @@ -932,6 +948,7 @@ describe('Logging Tests:', function() {
expect(_log[0]).to.have.property('remaining')
expect(_log[0]).to.have.property('function')
expect(_log[0]).to.have.property('memory')
expect(_log[0]).to.have.property('int')
expect(_log[0]).to.have.property('stack')

expect(_log[1]).to.have.property('time')
Expand Down

0 comments on commit 7d6c169

Please sign in to comment.