Better logs

This commit is contained in:
syuilo 2019-03-09 10:18:59 +09:00
parent 606e46e4d7
commit 539409faf8
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 27 additions and 25 deletions

View file

@ -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');
}

View file

@ -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;
}
}