Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
handle object circular reference
Browse files Browse the repository at this point in the history
Use util.inspect rather than JSON.stringify to short circuit circular references.
  • Loading branch information
ptdixon committed Apr 7, 2015
1 parent 4039374 commit 8f6f07c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/le_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ function Logger(ops){
if(a.length==2 && typeof(a[1])=='object'){
a[1].level = a[0];
if(options.timestamp) a[1].time = new Date().toISOString();
line+=' '+JSON.stringify(a[1]);
line+=' '+util.inspect(a[1]); // handles circular reference better than JSON.stringify
}else{
if(options.timestamp) line+=' '+new Date().toISOString();
for(var i in a) line+=' '+(typeof(a[i])=='object' ? JSON.stringify(a[i]) : a[i]);
for(var i in a) line+=' '+(typeof(a[i])=='object' ? util.inspect(a[i]) : a[i]); // handle circular ref...
}
line=line.replace(/\n/g, '\u2028');
que.push(line+'\n');
Expand Down

0 comments on commit 8f6f07c

Please sign in to comment.