mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
fix(json): removed try catch because circ json fixes typeerror
This commit is contained in:
parent
09a72eb17a
commit
3203efcb55
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user