Skip to content

Commit

Permalink
add try catch in logevent
Browse files Browse the repository at this point in the history
  • Loading branch information
krvikash35 committed Sep 25, 2016
1 parent bef3599 commit 483e2af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 12 additions & 2 deletions lib/logat.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ function logEvent(evname) {
params[i] = params[i].stack;
}
else if (typeof params[i] === 'object') {
params[i] = JSON.stringify(params[i], null, 3);
try {
params[i] = JSON.stringify(params[i], null, 3);
}
catch (e) {
params[i] = "logat: problem while stringify input param";
}
}
console.log('Object' + i + ': ', params[i]);
}
Expand All @@ -121,7 +126,12 @@ function logEvent(evname) {
params[i] = params[i].stack;
}
else if (typeof params[i] === 'object') {
params[i] = JSON.stringify(params[i], null, 3);
try {
params[i] = JSON.stringify(params[i], null, 3);
}
catch (e) {
params[i] = "logat: problem while stringify input param";
}
}
fs.appendFile(this.options.logFileName, params[i] + '\n' + 'Object' + i + ': ', function (err, msg) {
if (err) {
Expand Down
13 changes: 11 additions & 2 deletions lib/logat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ function logEvent(evname: string, ...params) {
if (params[i] instanceof Error) {
params[i] = params[i].stack
} else if (typeof params[i] === 'object') {
params[i] = JSON.stringify(params[i], null, 3)
try {
params[i] = JSON.stringify(params[i], null, 3)
} catch (e) {
params[i] = "logat: problem while stringify input param";
}

}
console.log('Object' + i + ': ', params[i])
}
Expand All @@ -111,7 +116,11 @@ function logEvent(evname: string, ...params) {
if (params[i] instanceof Error) {
params[i] = params[i].stack;
} else if (typeof params[i] === 'object') {
params[i] = JSON.stringify(params[i], null, 3)
try {
params[i] = JSON.stringify(params[i], null, 3)
} catch (e) {
params[i] = "logat: problem while stringify input param";
}
}
fs.appendFile(this.options.logFileName, params[i] + '\n' + 'Object' + i + ': ', (err, msg) => {
if (err) {
Expand Down

0 comments on commit 483e2af

Please sign in to comment.