ackee-node-logger
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -0,1 +1,6 @@ | ||
## [0.2.4] - 2018-09-06 | ||
### Added | ||
- `options.ignoredHttpMethods` to ignore certain HTTP requests in express middleware | ||
## [0.2.3] - 2018-09-06 | ||
@@ -2,0 +7,0 @@ |
@@ -17,2 +17,5 @@ const onFinished = require('on-finished'); | ||
const error = res[Symbol.for('error')]; | ||
if (this.options.ignoredHttpMethods.includes(req.method)) { | ||
return; | ||
} | ||
if (error) { | ||
@@ -19,0 +22,0 @@ this.error({ error, req, res, ackId: req.ackId }, `${reqInfo} - Error handler at the end of app`); |
@@ -72,2 +72,6 @@ const _ = require('lodash'); | ||
if (!options.ignoredHttpMethods) { | ||
options.ignoredHttpMethods = ['OPTIONS']; | ||
} | ||
const logger = pino( | ||
@@ -87,2 +91,3 @@ _.merge( | ||
logger.warning = logger.warn; | ||
logger.options = options; | ||
@@ -89,0 +94,0 @@ // Add maxLevel support to pino-multi-stream |
{ | ||
"name": "ackee-node-logger", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Ackee Node Logger", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -100,2 +100,3 @@ # Simple pino-based logger setup for Ackee purposes | ||
- `enableFields` - list of paths which will not be omitted by default serializers from objects being logged | ||
- `ignoredHttpMethods` - list of HTTP methods which will not be logged by express logging middleware at all. Defaults to `['OPTIONS']` | ||
- `streams` - list of stream objects, which will be passed directly to [pino-multistream's multistream function](https://github.com/pinojs/pino-multi-stream#pinomsmultistreamstreams) instead of default `ackee-node-logger` stream | ||
@@ -102,0 +103,0 @@ - `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` |
@@ -24,2 +24,3 @@ const express = require('express'); | ||
test('can use custom stream', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
@@ -32,2 +33,3 @@ streams: [ | ||
expect(json.message).toBe('Hello'); | ||
loggerWrites(); | ||
next(); | ||
@@ -41,5 +43,7 @@ }, | ||
logger.info('Hello'); | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
test('can use warning level', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
@@ -53,2 +57,3 @@ streams: [ | ||
expect(json.level).toBe(levels.warn); | ||
loggerWrites(); | ||
next(); | ||
@@ -62,2 +67,3 @@ }, | ||
logger.warning('Hello'); | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
@@ -72,1 +78,72 @@ | ||
}); | ||
test('GET requests are logged by default', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
expect(json.req.method).toBe('GET'); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request.get('/').then(() => { | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
}); | ||
test('OPTIONS requests are ignored by default', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request.options('/').then(() => { | ||
expect(loggerWrites).not.toBeCalled(); | ||
}); | ||
}); | ||
['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'].forEach(method => { | ||
test(`${method} HTTP method can be ignored by options`, () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
ignoredHttpMethods: [method], | ||
}); | ||
const app = express(); | ||
const request = supertest(app); | ||
app.use(logger.express); | ||
return request[method.toLowerCase()]('/').then(() => { | ||
expect(loggerWrites).not.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
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
23454
493
133