From 539409faf8c06e63cd85f1c96a85e916f336191e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 9 Mar 2019 10:18:59 +0900 Subject: [PATCH] Better logs --- src/queue/index.ts | 39 ++++++++++++++++----------------- src/queue/processors/deliver.ts | 13 ++++++----- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/queue/index.ts b/src/queue/index.ts index 31da4d1e75..3b3f0b72b5 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -25,25 +25,24 @@ export const deliverQueue = initializeQueue('deliver'); export const inboxQueue = initializeQueue('inbox'); export const dbQueue = initializeQueue('db'); +const deliverLogger = queueLogger.createSubLogger('deliver'); +const inboxLogger = queueLogger.createSubLogger('inbox'); + deliverQueue - .on('waiting', (jobId) => { - queueLogger.debug(`[deliver] waiting id=${jobId}`); - }) - .on('active', (job) => { - queueLogger.debug(`[deliver] active id=${job.id} to=${job.data.to}`); - }) - .on('completed', (job, result) => { - queueLogger.debug(`[deliver] completed(${result}) id=${job.id} to=${job.data.to}`); - }) - .on('failed', (job, err) => { - queueLogger.debug(`[deliver] failed(${err}) id=${job.id} to=${job.data.to}`); - }) - .on('error', (error) => { - queueLogger.error(`[deliver] error ${error}`); - }) - .on('stalled', (job) => { - queueLogger.warn(`[deliver] stalled id=${job.id} to=${job.data.to}`); - }); + .on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`)) + .on('active', (job) => deliverLogger.debug(`active id=${job.id} to=${job.data.to}`)) + .on('completed', (job, result) => deliverLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`)) + .on('failed', (job, err) => deliverLogger.debug(`failed(${err}) id=${job.id} to=${job.data.to}`)) + .on('error', (error) => deliverLogger.error(`error ${error}`)) + .on('stalled', (job) => deliverLogger.warn(`stalled id=${job.id} to=${job.data.to}`)); + +inboxQueue + .on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`)) + .on('active', (job) => inboxLogger.debug(`active id=${job.id} to=${job.data.to}`)) + .on('completed', (job, result) => inboxLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`)) + .on('failed', (job, err) => inboxLogger.debug(`failed(${err}) id=${job.id} to=${job.data.to}`)) + .on('error', (error) => inboxLogger.error(`error ${error}`)) + .on('stalled', (job) => inboxLogger.warn(`stalled id=${job.id} to=${job.data.to}`)); export function deliver(user: ILocalUser, content: any, to: any) { if (content == null) return null; @@ -146,12 +145,12 @@ export default function() { export function destroy() { deliverQueue.once('cleaned', (jobs, status) => { - queueLogger.succ(`[deliver] Cleaned ${jobs.length} ${status} jobs`); + deliverLogger.succ(`Cleaned ${jobs.length} ${status} jobs`); }); deliverQueue.clean(0, 'wait'); inboxQueue.once('cleaned', (jobs, status) => { - queueLogger.succ(`[inbox] Cleaned ${jobs.length} ${status} jobs`); + inboxLogger.succ(`Cleaned ${jobs.length} ${status} jobs`); }); inboxQueue.clean(0, 'wait'); } diff --git a/src/queue/processors/deliver.ts b/src/queue/processors/deliver.ts index 4cb1cfc6bb..28d3a17f6b 100644 --- a/src/queue/processors/deliver.ts +++ b/src/queue/processors/deliver.ts @@ -1,9 +1,11 @@ import * as Bull from 'bull'; import request from '../../remote/activitypub/request'; -import { queueLogger } from '../logger'; import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc'; import Instance from '../../models/instance'; import instanceChart from '../../services/chart/instance'; +import Logger from '../../services/logger'; + +const logger = new Logger('deliver'); let latest: string = null; @@ -11,8 +13,9 @@ export default async (job: Bull.Job) => { const { host } = new URL(job.data.to); try { - if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) - queueLogger.debug(`delivering ${latest}`); + if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) { + logger.debug(`delivering ${latest}`); + } await request(job.data.user, job.data.to, job.data.content); @@ -46,7 +49,7 @@ export default async (job: Bull.Job) => { }); if (res != null && res.hasOwnProperty('statusCode')) { - queueLogger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`); + logger.warn(`deliver failed: ${res.statusCode} ${res.statusMessage} to=${job.data.to}`); // 4xx if (res.statusCode >= 400 && res.statusCode < 500) { @@ -59,7 +62,7 @@ export default async (job: Bull.Job) => { throw `${res.statusCode} ${res.statusMessage}`; } else { // DNS error, socket error, timeout ... - queueLogger.warn(`deliver failed: ${res} to=${job.data.to}`); + logger.warn(`deliver failed: ${res} to=${job.data.to}`); throw res; } }