Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ackee-node-logger

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ackee-node-logger - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

src/express.js

8

CHANGELOG.md

@@ -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 @@

8

package.json
{
"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();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc