From 278e43e9ba2d0d8b9f9a29bb0c3da7070e84fe37 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 3 Feb 2019 04:04:57 +0900 Subject: [PATCH] [Server] Use logger for logging --- src/remote/logger.ts | 3 +++ src/remote/resolve-user.ts | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 src/remote/logger.ts diff --git a/src/remote/logger.ts b/src/remote/logger.ts new file mode 100644 index 000000000..41c36eaba --- /dev/null +++ b/src/remote/logger.ts @@ -0,0 +1,3 @@ +import Logger from "../misc/logger"; + +export const remoteLogger = new Logger('remote', 'blue'); diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index cae160e5f..6a89943ea 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -4,15 +4,15 @@ import webFinger from './webfinger'; import config from '../config'; import { createPerson, updatePerson } from './activitypub/models/person'; import { URL } from 'url'; -import * as debug from 'debug'; +import { remoteLogger } from './logger'; -const log = debug('misskey:remote:resolve-user'); +const logger = remoteLogger.createSubLogger('resolve-user'); export default async (username: string, _host: string, option?: any, resync?: boolean): Promise => { const usernameLower = username.toLowerCase(); if (_host == null) { - log(`return local user: ${usernameLower}`); + logger.info(`return local user: ${usernameLower}`); return await User.findOne({ usernameLower, host: null }); } @@ -23,7 +23,7 @@ export default async (username: string, _host: string, option?: any, resync?: bo const host = toUnicode(hostAscii); if (configHost == host) { - log(`return local user: ${usernameLower}`); + logger.info(`return local user: ${usernameLower}`); return await User.findOne({ usernameLower, host: null }); } @@ -34,18 +34,18 @@ export default async (username: string, _host: string, option?: any, resync?: bo if (user === null) { const self = await resolveSelf(acctLower); - log(`return new remote user: ${acctLower}`); + logger.info(`return new remote user: ${acctLower}`); return await createPerson(self.href); } if (resync) { - log(`try resync: ${acctLower}`); + logger.info(`try resync: ${acctLower}`); const self = await resolveSelf(acctLower); if ((user as IRemoteUser).uri !== self.href) { // if uri mismatch, Fix (user@host <=> AP's Person id(IRemoteUser.uri)) mapping. - log(`uri missmatch: ${acctLower}`); - console.log(`recovery missmatch uri for (username=${username}, host=${host}) from ${(user as IRemoteUser).uri} to ${self.href}`); + logger.info(`uri missmatch: ${acctLower}`); + logger.info(`recovery missmatch uri for (username=${username}, host=${host}) from ${(user as IRemoteUser).uri} to ${self.href}`); // validate uri const uri = new URL(self.href); @@ -62,21 +62,21 @@ export default async (username: string, _host: string, option?: any, resync?: bo } }); } else { - log(`uri is fine: ${acctLower}`); + logger.info(`uri is fine: ${acctLower}`); } await updatePerson(self.href); - log(`return resynced remote user: ${acctLower}`); + logger.info(`return resynced remote user: ${acctLower}`); return await User.findOne({ uri: self.href }); } - log(`return existing remote user: ${acctLower}`); +logger.info(`return existing remote user: ${acctLower}`); return user; }; async function resolveSelf(acctLower: string) { - log(`WebFinger for ${acctLower}`); + logger.info(`WebFinger for ${acctLower}`); const finger = await webFinger(acctLower); const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self'); if (!self) {