-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from makeros/feat/custom-field-schema
Feat/custom field schema
- Loading branch information
Showing
21 changed files
with
1,323 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ jobs: | |
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: npm test | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ jspm_packages | |
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"title": "GELF Schema", | ||
"type": "object", | ||
"properties": { | ||
"test1": { | ||
"type": "integer", | ||
"source": "nested.mock" | ||
}, | ||
"test2": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const dgram = jest.genMockFromModule('dgram'); // eslint-disable-line | ||
|
||
function createSocket() { | ||
function createSocket () { | ||
return { | ||
send: () => {}, | ||
close: () => {} | ||
}; | ||
} | ||
} | ||
|
||
dgram.createSocket = createSocket; | ||
dgram.createSocket = createSocket | ||
|
||
module.exports = dgram; | ||
module.exports = dgram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"title": "GELF Schema", | ||
"type": "object", | ||
"properties": { | ||
"_status_code": { | ||
"type": "integer", | ||
"source": "res.statusCode" | ||
}, | ||
"_user_agent": { | ||
"type": "string", | ||
"source": "req.headers.user-agent" | ||
}, | ||
"customField": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
const fastJsonParse = require('fast-json-parse'); | ||
const pipeline = require('./pipeline'); | ||
const pump = require('pump'); | ||
const split = require('split2'); | ||
const fastJsonParse = require('fast-json-parse') | ||
const pipeline = require('./pipeline') | ||
const pump = require('pump') | ||
const split = require('split2') | ||
|
||
module.exports = function (opts) { | ||
const pipe = pipeline(opts); | ||
pump(process.stdin, split(fastJsonParse), pipe); | ||
process.on('SIGINT', function () { process.exit(0); }); | ||
}; | ||
const pipe = pipeline(opts) | ||
pump(process.stdin, split(fastJsonParse), pipe) | ||
process.on('SIGINT', function () { process.exit(0) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
'use strict'; | ||
|
||
const through2 = require('through2'); | ||
const transformer = require('./transformer'); | ||
const Transport = require('./transport'); | ||
const utils = require('./utils'); | ||
const through2 = require('through2') | ||
const transformer = require('./transformer') | ||
const Transport = require('./transport') | ||
const utils = require('./utils') | ||
|
||
module.exports = function (opts) { | ||
return through2.obj(function (data, enc, cb) { | ||
if (data.value) { | ||
const transform = transformer(opts); | ||
const message = transform(data.value); | ||
|
||
const transform = transformer(opts) | ||
const message = transform(data.value) | ||
if (opts.verbose) { | ||
const stringify = utils.stringify(opts); | ||
const messageString = stringify(message); | ||
setImmediate(function () { process.stdout.write(messageString); }); | ||
const stringify = utils.stringify(opts) | ||
const messageString = stringify(message) | ||
setImmediate(function () { process.stdout.write(messageString + '\n') }) | ||
} | ||
|
||
const transport = new Transport(opts); | ||
transport.emit('log', message); | ||
const transport = new Transport(opts) | ||
transport.emit('log', message) | ||
} | ||
|
||
cb(); | ||
}); | ||
}; | ||
cb() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
'use strict'; | ||
const _ = require('lodash') | ||
|
||
const _ = require('lodash'); | ||
|
||
module.exports = function (data, customKeys) { | ||
return _.pick(data, customKeys); | ||
}; | ||
module.exports = function (data, customSchema) { | ||
// console.log(customSchema) | ||
return Object.entries(customSchema.properties) | ||
.reduce((acc, entry) => { | ||
const sourcePath = entry[1].source ? entry[1].source : entry[0] | ||
acc[entry[0]] = _.get(data, sourcePath, undefined) | ||
return acc | ||
}, {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
const _ = require('lodash'); | ||
const _ = require('lodash') | ||
|
||
const standardKeys = ['pid', 'hostname', 'name', 'level', 'time', 'msg', 'v']; | ||
const standardKeys = ['pid', 'hostname', 'name', 'level', 'time', 'msg', 'v'] | ||
|
||
function filterStandardKeys (data) { | ||
return Object | ||
.keys(data) | ||
.filter(function (key) { return !standardKeys.includes(key); }); | ||
.filter(function (key) { return !standardKeys.includes(key) }) | ||
} | ||
|
||
module.exports = function (data) { | ||
const expressKeys = filterStandardKeys(data); | ||
const expressGelf = _.pick(data, expressKeys); | ||
const expressKeys = filterStandardKeys(data) | ||
const expressGelf = _.pick(data, expressKeys) | ||
|
||
if(_.has(expressGelf, 'req') && _.has(expressGelf.req, 'headers')) { | ||
expressGelf.req.headers = JSON.stringify(expressGelf.req.headers); | ||
if (_.has(expressGelf, 'req') && _.has(expressGelf.req, 'headers')) { | ||
expressGelf.req.headers = JSON.stringify(expressGelf.req.headers) | ||
} | ||
|
||
if(_.has(expressGelf, 'res') && _.has(expressGelf.res, 'header')) { | ||
expressGelf.res.header = JSON.stringify(expressGelf.res.header); | ||
if (_.has(expressGelf, 'res') && _.has(expressGelf.res, 'header')) { | ||
expressGelf.res.header = JSON.stringify(expressGelf.res.header) | ||
} | ||
|
||
return expressGelf; | ||
}; | ||
return expressGelf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
const buildStandardGelf = require('./standard-gelf'); | ||
const buildExpressMiddlewareGelf = require('./express-gelf'); | ||
const buildCustomGelf = require('./custom-gelf'); | ||
const buildStandardGelf = require('./standard-gelf') | ||
const buildExpressMiddlewareGelf = require('./express-gelf') | ||
const buildCustomGelf = require('./custom-gelf') | ||
|
||
module.exports = function (opts) { | ||
return function (data) { | ||
const standardGelf = buildStandardGelf(data); | ||
const standardGelf = buildStandardGelf(data) | ||
|
||
const expressGelf = opts.useExpressMiddlewarePreset | ||
? buildExpressMiddlewareGelf(data) | ||
: {}; | ||
: {} | ||
|
||
const customGelf = opts.customKeys.length > 0 | ||
? buildCustomGelf(data, opts.customKeys) | ||
: {}; | ||
const customGelf = opts.customSchema | ||
? buildCustomGelf(data, opts.customSchema) | ||
: {} | ||
// return Object.assign({}, standardGelf, expressGelf, customGelf); | ||
// console.log(standardGelf, expressGelf, customGelf) | ||
const result = { | ||
...standardGelf, | ||
...expressGelf, | ||
...customGelf | ||
} | ||
// console.log(result) | ||
|
||
return Object.assign({}, standardGelf, expressGelf, customGelf); | ||
}; | ||
}; | ||
return result | ||
} | ||
} |
Oops, something went wrong.