pino-mongodb
Advanced tools
Comparing version 0.6.1 to 0.7.0
module.exports = function insert (data) { | ||
const jsonParse = this.jsonParse || require('fast-json-parse') | ||
let log = jsonParse(data) | ||
let log | ||
if (log.value) { | ||
log = log.value | ||
} else { | ||
try { | ||
log = JSON.parse(data) | ||
} catch (e) { | ||
log = { | ||
@@ -9,0 +8,0 @@ msg: data |
{ | ||
"name": "pino-mongodb", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Load pino logs into MongoDB", | ||
@@ -22,3 +22,5 @@ "main": "index.js", | ||
"mongodb", | ||
"pino-mongodb" | ||
"pino-mongodb", | ||
"logs", | ||
"logger" | ||
], | ||
@@ -33,3 +35,2 @@ "author": "ViktorKonsta", | ||
"commander": "^2.9.0", | ||
"fast-json-parse": "^1.0.2", | ||
"mongodb": "^2.2.11" | ||
@@ -36,0 +37,0 @@ }, |
@@ -18,4 +18,4 @@ #!/usr/bin/env node | ||
.option('-c, --collection <name>', 'set database collection (logs)', 'logs') | ||
.option('-u, --user <username>', 'set database username', undefined) | ||
.option('-p, --pass <password>', 'set database password', undefined) | ||
.option('-u, --user <username>', 'set database username') | ||
.option('-p, --pass <password>', 'set database password') | ||
.option('-q, --quiet', 'suppress stdin to stdout output (false)', false) | ||
@@ -25,9 +25,2 @@ .option('--show-insert-errors', 'show errors from inserting documents into mongodb (true)', true) | ||
program.host = process.env.DB_HOST || program.host | ||
program.port = process.env.DB_PORT || program.port | ||
program.db = process.env.DB_NAME || program.db | ||
program.collection = process.env.DB_COLLECTION || program.collection | ||
program.user = process.env.DB_USER || program.user | ||
program.pass = process.env.DB_PASS || program.pass | ||
const rl = readline.createInterface({ | ||
@@ -34,0 +27,0 @@ input: process.stdin, |
# pino-mongodb | ||
[](https://github.com/feross/standard) | ||
@@ -6,2 +7,5 @@ | ||
Actually it will convert any data from `stdin` (not just `pino` logs) and if it can parse it | ||
as `JSON` then it will insert that into `mongo` otherwise it will insert that as it is but with `msg` field. | ||
## Install | ||
@@ -15,28 +19,6 @@ | ||
It takes `process.stdin` stream, parses the data and tries to insert that data into | ||
`mongodb`. | ||
### With server use it like this | ||
``` | ||
node server.js | pino-mongodb [options] | ||
node my-app.js | pino-mongodb [options] | ||
``` | ||
### Options | ||
To define db connection you can either specify configuration with `args` or with `env` | ||
env | describe | ||
:--- | :--- | ||
`DB_HOST` | DataBase host | ||
`DB_PORT` | DataBase port | ||
`DB_NAME` | DataBase name | ||
`DB_COLLECTION` | DataBase collection name | ||
`DB_USER` | DataBase username | ||
`DB_PASS` | DataBase password | ||
**Note**: if `env` variable is defined then `argv` variable will be ignored | ||
### Help | ||
``` | ||
@@ -43,0 +25,0 @@ Usage: pino-mongodb [options] |
@@ -16,6 +16,2 @@ const t = require('tap') | ||
const context = { | ||
jsonParse: sinon.stub().returns({ | ||
err: null, | ||
value | ||
}), | ||
program: {}, | ||
@@ -27,5 +23,3 @@ collection: { | ||
insert.call(context, valueStr) | ||
t.equal(context.jsonParse.callCount, 1, 'jsonParse should be called once') | ||
t.equal(context.collection.insertOne.callCount, 1, 'insertOne should be called once') | ||
t.equal(context.jsonParse.args[0][0], valueStr, 'jsonParse first argument should equals valueStr') | ||
t.deepEqual(context.collection.insertOne.args[0][0], value, 'insertOne first argument should equals value') | ||
@@ -38,6 +32,2 @@ t.end() | ||
const context = { | ||
jsonParse: sinon.stub().returns({ | ||
err: new Error(), | ||
value: null | ||
}), | ||
program: {}, | ||
@@ -52,5 +42,3 @@ collection: { | ||
insert.call(context, value) | ||
t.equal(context.jsonParse.callCount, 1, 'jsonParse should be called once') | ||
t.equal(context.collection.insertOne.callCount, 1, 'insertOne should be called once') | ||
t.equal(context.jsonParse.args[0][0], value, 'jsonParse first argument should equals valueStr') | ||
t.deepEqual(context.collection.insertOne.args[0][0], log, 'insertOne first argument should equals value') | ||
@@ -57,0 +45,0 @@ t.end() |
@@ -33,2 +33,1 @@ const t = require('tap') | ||
}) | ||
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
2
0
7392
131
50
- Removedfast-json-parse@^1.0.2
- Removedfast-json-parse@1.0.3(transitive)