Skip to content

Commit

Permalink
Fix #953 ログ書き込みのエラーハンドルの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Mar 7, 2021
1 parent 7b43225 commit 22a5ce8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/boot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ if (!program.quiet) {

// Display detail of uncaught exception
process.on('uncaughtException', err => {
logger.error(err);
try {
logger.error(err);
} catch { }
});

// Dying away...
Expand Down
8 changes: 5 additions & 3 deletions src/services/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Logger {
level === 'info' ? this.syslogClient.info :
null as never;

send.bind(this.syslogClient)(message);
send.bind(this.syslogClient)(message).catch(() => {});
} else {
const Logs = getRepository(Log);
Logs.insert({
Expand All @@ -105,7 +105,7 @@ export default class Logger {
level: level,
message: message.substr(0, 1000), // 1024を超えるとログが挿入できずエラーになり無限ループする
data: data,
} as Log);
} as Log).catch(() => {});
}
}
}
Expand All @@ -115,8 +115,10 @@ export default class Logger {
data = data || {};
data.e = x;
this.log('error', x.toString(), data, important);
} else if (typeof x === 'object') {
this.log('error', `${(x as any).message || (x as any).name || x}`, data, important);
} else {
this.log('error', x, data, important);
this.log('error', `${x}`, data, important);
}
}

Expand Down

0 comments on commit 22a5ce8

Please sign in to comment.