fix(json): removed try catch because circ json fixes typeerror

This commit is contained in:
Gareth Jones 2018-02-08 08:12:17 +11:00
parent 09a72eb17a
commit 3203efcb55

View File

@ -21,33 +21,19 @@ class LoggingEvent {
this.level = level;
this.context = Object.assign({}, context);
this.pid = process.pid;
// if (cluster && cluster.isWorker) {
// this.cluster = {
// workerId: cluster.worker.id,
// worker: process.pid
// };
// }
}
serialise() {
try {
const logData = this.data.map((e) => {
// JSON.stringify(new Error('test')) returns {}, which is not really useful for us.
// The following allows us to serialize errors correctly.
if (e && e.stack && CircularJSON.stringify(e) === '{}') {
e = { message: e.message, stack: e.stack };
}
return e;
});
this.data = logData;
return CircularJSON.stringify(this);
} catch (e) {
return new LoggingEvent(
'log4js',
levels.ERROR,
['Unable to serialise log event due to :', e]
).serialise();
}
const logData = this.data.map((e) => {
// JSON.stringify(new Error('test')) returns {}, which is not really useful for us.
// The following allows us to serialize errors correctly.
if (e && e.stack && CircularJSON.stringify(e) === '{}') {
e = { message: e.message, stack: e.stack };
}
return e;
});
this.data = logData;
return CircularJSON.stringify(this);
}
static deserialise(serialised) {