Merge branch 'dgaubert/ch78384/maps-api-replace-log4js-logger-by-pino-bis-bis' into dgaubert/ch78384/maps-api-replace-log4js-logger-by-pino-bis-bis-bis

This commit is contained in:
Daniel García Aubert 2020-06-08 19:31:18 +02:00
commit 04d0f2e530

View File

@ -2,8 +2,9 @@
const split = require('split2'); const split = require('split2');
const assingDeep = require('assign-deep'); const assingDeep = require('assign-deep');
const logs = new Map();
const { Transform } = require('readable-stream'); const { Transform } = require('readable-stream');
const DEV_ENVS = ['test', 'development'];
const logs = new Map();
const LEVELS = { const LEVELS = {
10: 'trace', 10: 'trace',
@ -21,8 +22,15 @@ function logTransport () {
try { try {
entry = JSON.parse(chunk); entry = JSON.parse(chunk);
} catch (error) { const { level, time } = entry;
// this.push(chunk + '\n');
if (level === undefined && time === undefined) {
throw new Error('Entry log is not a valid');
}
} catch (e) {
if (DEV_ENVS.includes(process.env.NODE_ENV)) {
this.push(chunk + '\n');
}
return callback(); return callback();
} }
@ -51,7 +59,7 @@ function logTransport () {
} }
let error; let error;
if (Object.prototype.hasOwnProperty.call(accEntry, 'error') && Object.prototype.hasOwnProperty.call(entry, 'error')) { if (hasProperty(accEntry, 'error') && hasProperty(entry, 'error')) {
logs.set(id, assingDeep({}, accEntry, entry, { error: accEntry.error.concat(entry.error) })); logs.set(id, assingDeep({}, accEntry, entry, { error: accEntry.error.concat(entry.error) }));
} else { } else {
logs.set(id, assingDeep({}, accEntry, entry)); logs.set(id, assingDeep({}, accEntry, entry));
@ -65,6 +73,10 @@ function logTransport () {
}) })
} }
function hasProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop)
}
process.stdin process.stdin
.pipe(split()) .pipe(split())
.pipe(logTransport()) .pipe(logTransport())