@binxhealth/pino-stackdriver
Advanced tools
Comparing version 1.1.0 to 3.0.0
36
index.js
@@ -1,23 +0,5 @@ | ||
#!/usr/bin/env node | ||
const split = require('split2') | ||
const parseJson = require('fast-json-parse') | ||
const fastJson = require('fast-json-stringify') | ||
const pumpify = require('pumpify') | ||
const stringifyJson = fastJson({ | ||
type: 'object', | ||
properties: { | ||
time: { type: 'string' }, | ||
hostname: { type: 'string' }, | ||
level: { type: 'integer' }, | ||
msg: { type: 'string' }, | ||
pid: { type: 'integer' }, | ||
req: { type: 'object', additionalProperties: true }, | ||
res: { type: 'object', additionalProperties: true }, | ||
responseTime: { type: 'integer' }, | ||
v: { type: 'integer' }, | ||
severity: { type: 'string' } | ||
} | ||
}) | ||
function pinoStackdriver (line) { | ||
@@ -29,9 +11,11 @@ const { value } = parseJson(line) | ||
case 20: value.severity = 'DEBUG'; break | ||
case 30: value.severity = 'INFO'; break | ||
case 40: value.severity = 'WARNING'; break | ||
case 50: value.severity = 'ERROR'; break | ||
case 60: value.severity = 'CRITICAL'; break | ||
default: value.severity = 'INFO' | ||
} | ||
value.time = new Date(value.time).toISOString() | ||
line = stringifyJson(value) | ||
if (value.time) { | ||
value.time = new Date(value.time).toISOString() | ||
} | ||
line = JSON.stringify(value) | ||
} | ||
@@ -41,2 +25,8 @@ return line + '\n' | ||
process.stdin.pipe(split(pinoStackdriver)).pipe(process.stdout) | ||
const transform = split(pinoStackdriver) | ||
function createStream () { | ||
return pumpify(transform, process.stdout) | ||
} | ||
module.exports = { transform, createStream } |
{ | ||
"name": "@binxhealth/pino-stackdriver", | ||
"version": "1.1.0", | ||
"version": "3.0.0", | ||
"description": "A utility that makes express-pino logs StackDriver-compatible", | ||
"main": "index.js", | ||
"bin": { | ||
"pino-stackdriver": "index.js" | ||
"pino-stackdriver": "cli.js" | ||
}, | ||
@@ -30,10 +30,11 @@ "scripts": { | ||
"fast-json-parse": "^1.0.3", | ||
"fast-json-stringify": "^1.15.3", | ||
"pumpify": "^2.0.1", | ||
"split2": "^3.1.1" | ||
}, | ||
"devDependencies": { | ||
"@ianwalter/bff": "^5.2.1", | ||
"@ianwalter/eslint-config": "^2.0.1", | ||
"execa": "^1.0.0", | ||
"np": "^5.0.3" | ||
"@ianwalter/bff": "^7.0.0", | ||
"@ianwalter/eslint-config": "^3.1.0", | ||
"@ianwalter/release": "^3.0.6", | ||
"@ianwalter/renovate-config": "^1.2.0", | ||
"execa": "^3.3.0" | ||
}, | ||
@@ -45,3 +46,13 @@ "eslintConfig": { | ||
] | ||
}, | ||
"renovate": { | ||
"extends": [ | ||
"@ianwalter" | ||
] | ||
}, | ||
"release": { | ||
"registries": [ | ||
"github" | ||
] | ||
} | ||
} |
@@ -1,8 +0,10 @@ | ||
# pino-stackdriver | ||
# @binxhealth/pino-stackdriver | ||
> A utility that makes express-[pino][pinoUrl] logs StackDriver-compatible | ||
[![CI][ciImage]][ciUrl] | ||
## Installation | ||
```console | ||
npm install @binxhealth/pino-stackdriver --save | ||
yarn add @binxhealth/pino-stackdriver --dev | ||
``` | ||
@@ -22,3 +24,20 @@ | ||
Or create a new stream and pass it to [pino][pinoUrl] | ||
```javascript | ||
import { createStream } from '@binxhealth/pino-stackdriver'; | ||
const logger = pino( | ||
{ | ||
level: 'debug', | ||
}, | ||
createStream() | ||
); | ||
logger.info('This works the same as usual...'); | ||
logger.error('...and will log to stdout with the correct Stackdriver format'); | ||
``` | ||
[pinoUrl]: http://getpino.io/#/ | ||
[ciImage]: https://github.com/binxhealth/pino-stackdriver/workflows/CI/badge.svg | ||
[ciUrl]: https://github.com/binxhealth/pino-stackdriver/actions |
@@ -6,3 +6,3 @@ const { join } = require('path') | ||
const pinoStackdriver = join(__dirname, '../') | ||
const pinoStackdriver = join(__dirname, '../cli') | ||
const lineOne = JSON.stringify({ | ||
@@ -30,2 +30,3 @@ time: 1544043395681, | ||
}) + '\n' | ||
const lineThree = "{ Error => `Lalala-la lalal-la Elmo's world!` }" | ||
@@ -35,17 +36,24 @@ test('pino-stackdriver adds severity to log entry', ({ expect }) => { | ||
const stdin = new Readable({ read () {} }) | ||
const cp = execa('node', [pinoStackdriver]) | ||
let counter = 0 | ||
const cp = execa('node', [pinoStackdriver], { reject: false }) | ||
let lines = [] | ||
cp.stdout.on('data', data => { | ||
expect(JSON.parse(data)).toMatchSnapshot() | ||
if (counter) { | ||
resolve() | ||
} else { | ||
counter++ | ||
} | ||
const rawLines = data.toString().split('\n') | ||
lines = lines.concat(rawLines.filter(line => line)) | ||
}) | ||
cp.stdout.on('close', () => { | ||
expect(lines).toMatchSnapshot() | ||
resolve() | ||
}) | ||
// Write logs to stream. | ||
stdin.pipe(cp.stdin) | ||
stdin.push(lineOne) | ||
stdin.push(lineTwo) | ||
stdin.push(null) // Push null to close the stream. | ||
stdin.push(lineThree) | ||
// Push null to close the streams. | ||
stdin.push(null) | ||
cp.stdin.push(null) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
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
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
7508
9
43
0
5
80
+ Addedpumpify@^2.0.1
+ Addedduplexify@4.1.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedpumpify@2.0.1(transitive)
+ Addedstream-shift@1.0.3(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedfast-json-stringify@^1.15.3
- Removedajv@6.12.6(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-json-stringify@1.21.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedstring-similarity@4.0.4(transitive)
- Removeduri-js@4.4.1(transitive)