mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
Fixed serialise() for NaN, Infinity, -Infinity and undefined
This commit is contained in:
parent
2f29d0a0f5
commit
ceb06bed61
@ -35,9 +35,20 @@ class LoggingEvent {
|
||||
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.
|
||||
// duck-typing for Error object
|
||||
if (e && e.message && e.stack) {
|
||||
e = Object.assign({ message: e.message, stack: e.stack }, e);
|
||||
}
|
||||
// JSON.stringify({a: parseInt('abc'), b: 1/0, c: -1/0}) returns {a: null, b: null, c: null}.
|
||||
// The following allows us to serialize to NaN, Infinity and -Infinity correctly.
|
||||
else if (typeof e === 'number' && (isNaN(e) || !isFinite(e))) {
|
||||
e = e.toString();
|
||||
}
|
||||
// JSON.stringify([undefined]) returns [null].
|
||||
// The following allows us to serialize to undefined correctly.
|
||||
else if (typeof e === 'undefined') {
|
||||
e = typeof e;
|
||||
}
|
||||
return e;
|
||||
});
|
||||
this.data = logData;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user