ackee-node-logger
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -0,1 +1,7 @@ | ||
## [0.2.5] - 2018-09-10 | ||
### Added | ||
- log object are automatically enhanced for Google Stackdriver | ||
- `options.disableStackdriverFormat` to prevent logger from modifying log objects | ||
## [0.2.4] - 2018-09-06 | ||
@@ -2,0 +8,0 @@ |
12
index.js
@@ -7,2 +7,3 @@ const _ = require('lodash'); | ||
const { expressMiddleware, expressErrorMiddleware } = require('./express'); | ||
const { StackDriverFormatStream } = require('./stackdriver'); | ||
@@ -72,2 +73,13 @@ // This is a custom slightly edited version of pino-multistream's wirte method, whch adds support for maximum log level | ||
} | ||
if (!_.get(options, 'disableStackdriverFormat', false)) { | ||
streams = streams.map(stream => { | ||
const newStream = new StackDriverFormatStream(); | ||
newStream.pipe(stream.stream); | ||
return { | ||
level: stream.level, | ||
maxLevel: stream.maxLevel, | ||
stream: newStream, | ||
}; | ||
}); | ||
} | ||
@@ -74,0 +86,0 @@ if (!options.ignoredHttpMethods) { |
{ | ||
"name": "ackee-node-logger", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Ackee Node Logger", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -103,2 +103,3 @@ # Simple pino-based logger setup for Ackee purposes | ||
- `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 | ||
- `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) | ||
@@ -105,0 +106,0 @@ |
@@ -144,1 +144,44 @@ const express = require('express'); | ||
}); | ||
test('severity field is automatically added to log object', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
expect(json.severity).toBe('CRITICAL'); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
logger.fatal('Hello'); | ||
expect(loggerWrites).toBeCalled(); | ||
}); | ||
test('automatic severity field can be disabled by options', () => { | ||
const loggerWrites = jest.fn(); | ||
const logger = loggerFactory({ | ||
disableStackdriverFormat: true, | ||
streams: [ | ||
{ | ||
stream: new stream.Writable({ | ||
write: (chunk, encoding, next) => { | ||
const json = JSON.parse(chunk); | ||
expect(json.severity).toBe(undefined); | ||
loggerWrites(); | ||
next(); | ||
}, | ||
}), | ||
}, | ||
], | ||
}); | ||
logger.fatal('Hello'); | ||
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
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
26009
15
562
134