From 51cc3164b27746e896242a98a32d5f8700a38dd4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 7 Nov 2022 12:27:43 +0100 Subject: [PATCH] use logger instead of console --- backend/src/federation/index.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/src/federation/index.ts b/backend/src/federation/index.ts index 2ff43385f..d91e1f2ee 100644 --- a/backend/src/federation/index.ts +++ b/backend/src/federation/index.ts @@ -1,9 +1,9 @@ -/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import DHT from '@hyperswarm/dht' import { Connection } from '@dbTools/typeorm' +import { backendLogger as logger } from '@/server/logger' function between(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1) + min) @@ -23,8 +23,6 @@ const nodeAPI = { export const startDHT = async (connection: Connection, topic: string): Promise => { try { - console.log('topic', topic, typeof topic) - const TOPIC = DHT.hash(Buffer.from(topic)) const keyPair = DHT.keyPair() @@ -36,10 +34,10 @@ export const startDHT = async (connection: Connection, topic: string): Promise console.log('data:', data.toString('ascii'))) + socket.on('data', (data: Buffer) => logger.info(`data: ${data.toString('ascii')}`)) // process.stdin.pipe(noiseSocket).pipe(process.stdout); }) @@ -47,7 +45,7 @@ export const startDHT = async (connection: Connection, topic: string): Promise { - console.log('Announcing on topic:', TOPIC.toString('hex')) + logger.info(`Announcing on topic: ${TOPIC.toString('hex')}`) await node.announce(TOPIC, keyPair).finished() }, ANNOUNCETIME) @@ -55,12 +53,12 @@ export const startDHT = async (connection: Connection, topic: string): Promise { - console.log('Refreshing successful nodes') + logger.info('Refreshing successful nodes') successfulRequests = [] }, SUCCESSTIME) setInterval(async () => { - console.log('Refreshing errorful nodes') + logger.info('Refreshing errorful nodes') errorfulRequests = [] }, ERRORTIME) @@ -86,7 +84,7 @@ export const startDHT = async (connection: Connection, topic: string): Promise { // publicKey here is keyPair.publicKey from above @@ -102,7 +100,7 @@ export const startDHT = async (connection: Connection, topic: string): Promise { errorfulRequests.push(remotePubKey) - console.log(`error on peer ${remotePubKey}: ${err.message}`) + logger.error(`error on peer ${remotePubKey}: ${err.message}`) }) socket.on('open', function () { @@ -117,6 +115,6 @@ export const startDHT = async (connection: Connection, topic: string): Promise