enhance(backend): loggerでデータの表示にutil.inspectを使用する
This commit is contained in:
parent
13f5fafdbc
commit
f7e8862d28
2 changed files with 18 additions and 12 deletions
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import cluster from 'node:cluster';
|
import cluster from 'node:cluster';
|
||||||
|
import { inspect } from 'node:util';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { default as convertColor } from 'color-convert';
|
import { default as convertColor } from 'color-convert';
|
||||||
import { format as dateFormat } from 'date-fns';
|
import { format as dateFormat } from 'date-fns';
|
||||||
|
@ -73,7 +74,16 @@ export default class Logger {
|
||||||
|
|
||||||
const args: unknown[] = [important ? chalk.bold(log) : log];
|
const args: unknown[] = [important ? chalk.bold(log) : log];
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
args.push(data);
|
args.push(inspect(data, {
|
||||||
|
depth: Infinity,
|
||||||
|
compact: true,
|
||||||
|
breakLength: Infinity,
|
||||||
|
colors: true,
|
||||||
|
showHidden: false,
|
||||||
|
showProxy: false,
|
||||||
|
maxArrayLength: Infinity,
|
||||||
|
maxStringLength: Infinity,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
console.log(...args);
|
console.log(...args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,11 +120,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
||||||
|
|
||||||
function renderError(e: Error): any {
|
function renderError(e: Error): any {
|
||||||
if (e) { // 何故かeがundefinedで来ることがある
|
if (e) { // 何故かeがundefinedで来ることがある
|
||||||
return {
|
return e;
|
||||||
stack: e.stack,
|
|
||||||
message: e.message,
|
|
||||||
name: e.name,
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
stack: '?',
|
stack: '?',
|
||||||
|
@ -155,8 +151,8 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
||||||
this.systemQueueWorker
|
this.systemQueueWorker
|
||||||
.on('active', (job) => systemLogger.debug(`active id=${job.id}`))
|
.on('active', (job) => systemLogger.debug(`active id=${job.id}`))
|
||||||
.on('completed', (job, result) => systemLogger.debug(`completed(${result}) id=${job.id}`))
|
.on('completed', (job, result) => systemLogger.debug(`completed(${result}) id=${job.id}`))
|
||||||
.on('failed', (job, err) => systemLogger.warn(`failed(${err.stack}) id=${job ? job.id : '-'}`, { job, e: renderError(err) }))
|
.on('failed', (job, err) => systemLogger.warn(`failed id=${job ? job.id : '-'}`, { data: job?.data, e: renderError(err) }))
|
||||||
.on('error', (err: Error) => systemLogger.error(`error ${err.stack}`, { e: renderError(err) }))
|
.on('error', (err: Error) => systemLogger.error(`error`, { e: renderError(err) }))
|
||||||
.on('stalled', (jobId) => systemLogger.warn(`stalled id=${jobId}`));
|
.on('stalled', (jobId) => systemLogger.warn(`stalled id=${jobId}`));
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
@ -218,8 +214,8 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
||||||
this.deliverQueueWorker
|
this.deliverQueueWorker
|
||||||
.on('active', (job) => deliverLogger.debug(`active ${getJobInfo(job, true)} to=${job.data.to}`))
|
.on('active', (job) => deliverLogger.debug(`active ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||||
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) ${getJobInfo(job, true)} to=${job.data.to}`))
|
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) ${getJobInfo(job, true)} to=${job.data.to}`))
|
||||||
.on('failed', (job, err) => deliverLogger.warn(`failed(${err.stack}) ${getJobInfo(job)} to=${job ? job.data.to : '-'}`))
|
.on('failed', (job, err) => deliverLogger.warn(`failed ${getJobInfo(job)} id=${job ? job.id : '-'} to=${job?.data.to}`, { data: job?.data, e: renderError(err) }))
|
||||||
.on('error', (err: Error) => deliverLogger.error(`error ${err.stack}`, { e: renderError(err) }))
|
.on('error', (err: Error) => deliverLogger.error('error', { e: renderError(err) }))
|
||||||
.on('stalled', (jobId) => deliverLogger.warn(`stalled id=${jobId}`));
|
.on('stalled', (jobId) => deliverLogger.warn(`stalled id=${jobId}`));
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
@ -242,8 +238,8 @@ export class QueueProcessorService implements OnApplicationShutdown {
|
||||||
this.inboxQueueWorker
|
this.inboxQueueWorker
|
||||||
.on('active', (job) => inboxLogger.debug(`active ${getJobInfo(job, true)}`))
|
.on('active', (job) => inboxLogger.debug(`active ${getJobInfo(job, true)}`))
|
||||||
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) ${getJobInfo(job, true)}`))
|
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) ${getJobInfo(job, true)}`))
|
||||||
.on('failed', (job, err) => inboxLogger.warn(`failed(${err.stack}) ${getJobInfo(job)} activity=${job ? (job.data.activity ? job.data.activity.id : 'none') : '-'}`, { job, e: renderError(err) }))
|
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) ${getJobInfo(job)} activity=${job ? (job.data.activity ? job.data.activity.id : 'none') : '-'}`, { data: job?.data, e: renderError(err) }))
|
||||||
.on('error', (err: Error) => inboxLogger.error(`error ${err.stack}`, { e: renderError(err) }))
|
.on('error', (err: Error) => inboxLogger.error(`error ${err}`, { e: renderError(err) }))
|
||||||
.on('stalled', (jobId) => inboxLogger.warn(`stalled id=${jobId}`));
|
.on('stalled', (jobId) => inboxLogger.warn(`stalled id=${jobId}`));
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue