ackee-node-logger
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -0,1 +1,9 @@ | ||
## [0.2.8] - 2018-10-15 | ||
### Changed | ||
- output format of express middleware logging | ||
### Fixed | ||
- bug in `enableFields` options | ||
## [0.2.7] - 2018-10-10 | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "ackee-node-logger", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Ackee Node Logger", | ||
@@ -26,6 +26,6 @@ "main": "index.js", | ||
"lodash.isstring": "^4.0.1", | ||
"lodash.pick": "^4.4.0", | ||
"omit-deep": "^0.3.0", | ||
"on-finished": "^2.3.0", | ||
"on-headers": "^1.0.1", | ||
"pick-deep": "^1.0.0", | ||
"pino": "^4.13.0", | ||
@@ -41,2 +41,3 @@ "pino-multi-stream": "3.1.2" | ||
"jest": "^22.4.2", | ||
"jest-expect-message": "^1.0.1", | ||
"lint-staged": "^7.0.0", | ||
@@ -47,3 +48,6 @@ "npm-check": "^5.5.2", | ||
"supertest": "^3.1.0" | ||
}, | ||
"jest": { | ||
"setupTestFrameworkScriptFile": "jest-expect-message" | ||
} | ||
} |
@@ -83,3 +83,3 @@ # Simple pino-based logger setup for Ackee purposes | ||
All those log messages will contain request and possibly response, error, time from request to response and status code. | ||
All those log messages will contain request and possibly response, error, time from request to response, status code and `user-agent`, `x-deviceid` and `authorization` request headers. | ||
@@ -104,3 +104,3 @@ ## Environment-specific behavior | ||
- `pretty` - if set to `true`, logger will use [pino pretty human-readable logs](https://github.com/pinojs/pino/blob/master/docs/API.md#pretty). This option can be overriden by `streams` | ||
- `disableStackdriverFormat` - if set to `true`, logger will add `severity` field to all log objects, so that log levels in Google Stackdriver work as expected. Defaults to `true` | ||
- `disableStackdriverFormat` - if set to `false`, logger will add `severity` field to all log objects, so that log levels in Google Stackdriver work as expected. Defaults to `false` | ||
- `config` - object, which will be passed to underlying logger object. Right now, underlying logger is [pino](https://github.com/pinojs/pino), so for available options see [pino API docs](https://github.com/pinojs/pino/blob/master/docs/API.md#pinooptions-stream) | ||
@@ -107,0 +107,0 @@ |
@@ -1,4 +0,6 @@ | ||
const pick = require('lodash.pick'); | ||
const pick = require('pick-deep'); | ||
const omitDeep = require('omit-deep'); | ||
const stream = require('stream'); | ||
const express = require('express'); | ||
const supertest = require('supertest'); | ||
@@ -175,1 +177,94 @@ let loggerFactory; | ||
}); | ||
test('Some express headers are enabled by default', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
const validHeaders = ['x-deviceid', 'authorization', 'user-agent']; | ||
validHeaders.forEach(header => | ||
expect(json.req.headers[header], `${header} header should be defined`).toBeDefined() | ||
); | ||
Object.keys(json.req.headers).forEach(header => | ||
expect(validHeaders.includes(header), `${header} header should not be defined`).toBe(true) | ||
); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request | ||
.get('/') | ||
.set('x-deviceid', '12345abcde') | ||
.set('Authorization', 'Basic pass') | ||
.set('User-Agent', 'Jest tests') | ||
.set('Age', 100) | ||
.then(() => { | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
}); | ||
test('Express fields and headers can be enabled', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
enableFields: ['req.protocol', 'req.headers.host'], | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
expect(json.req.protocol).toBe('http'); | ||
expect(json.req.headers.host).toBe('localhost'); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request | ||
.get('/') | ||
.set('host', 'localhost') | ||
.then(() => { | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
}); | ||
test('Default express headers can be disabled', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
disableFields: ['req.headers.user-agent'], | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
expect(json.req.headers['user-agent']).toBeUndefined(); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request | ||
.get('/') | ||
.set('x-deviceid', '1234') | ||
.then(() => { | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33602
12
17
753
+ Addedpick-deep@^1.0.0
+ Added@strikeentco/get@1.0.1(transitive)
+ Added@strikeentco/set@1.0.2(transitive)
+ Addedpick-deep@1.0.0(transitive)
- Removedlodash.pick@^4.4.0
- Removedlodash.pick@4.4.0(transitive)