From 5696e3beba9453e5981a599bab2662d87dc1ddd2 Mon Sep 17 00:00:00 2001 From: Akim <59872966+akim-bow@users.noreply.github.com> Date: Wed, 17 Jan 2024 18:30:10 +0700 Subject: [PATCH] fix(js-client): Improve logging (#418) * Improve logging * Improve further connection logs --- .../src/connection/RelayConnection.ts | 28 +++++++++++-------- .../core/js-client/src/jsPeer/FluencePeer.ts | 7 ++++- packages/core/js-client/src/util/logger.ts | 12 -------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/core/js-client/src/connection/RelayConnection.ts b/packages/core/js-client/src/connection/RelayConnection.ts index f568a86a..07ddb44f 100644 --- a/packages/core/js-client/src/connection/RelayConnection.ts +++ b/packages/core/js-client/src/connection/RelayConnection.ts @@ -18,7 +18,7 @@ import { noise } from "@chainsafe/libp2p-noise"; import { yamux } from "@chainsafe/libp2p-yamux"; import { PeerIdB58 } from "@fluencelabs/interfaces"; import { identify } from "@libp2p/identify"; -import type { PeerId, Stream } from "@libp2p/interface"; +import type { PeerId } from "@libp2p/interface"; import { peerIdFromString } from "@libp2p/peer-id"; import { ping } from "@libp2p/ping"; import { webSockets } from "@libp2p/websockets"; @@ -180,33 +180,39 @@ export class RelayConnection implements IConnection { ); } - log.trace("sending particle..."); - // Reusing active connection here const stream = await this.lib2p2Peer.dialProtocol( this.relayAddress, PROTOCOL_NAME, ); - log.trace("created stream with id ", stream.id); + log.trace( + "sending particle %s to %s", + particle.id, + this.relayAddress.toString(), + ); + const sink = stream.sink; await pipe([fromString(serializeToString(particle))], encode, sink); - log.trace("data written to sink"); + + log.trace( + "particle %s sent to %s", + particle.id, + this.relayAddress.toString(), + ); } - // Await will appear after uncommenting lines in func body - // eslint-disable-next-line @typescript-eslint/require-await - private async processIncomingMessage(msg: string, stream: Stream) { + private async processIncomingMessage(msg: string) { let particle: Particle | undefined; try { particle = Particle.fromString(msg); log.trace( - "got particle from stream with id %s and particle id %s", - stream.id, + "received particle %s from %s", particle.id, + this.relayAddress.toString(), ); const initPeerId = peerIdFromString(particle.initPeerId); @@ -268,7 +274,7 @@ export class RelayConnection implements IConnection { async (source) => { try { for await (const msg of source) { - await this.processIncomingMessage(msg, stream); + await this.processIncomingMessage(msg); } } catch (e) { log.error("connection closed: %j", e); diff --git a/packages/core/js-client/src/jsPeer/FluencePeer.ts b/packages/core/js-client/src/jsPeer/FluencePeer.ts index a6de998e..c2402193 100644 --- a/packages/core/js-client/src/jsPeer/FluencePeer.ts +++ b/packages/core/js-client/src/jsPeer/FluencePeer.ts @@ -424,8 +424,13 @@ export abstract class FluencePeer { ): Promise { const particleId = req.particleContext.particleId; + log_particle.debug("id %s. executing call service handler %j", particleId, { + serviceId: req.serviceId, + functionName: req.fnName, + }); + log_particle.trace( - "id %s. executing call service handler %j", + "id %s. executing call service handler detailed %j", particleId, req, ); diff --git a/packages/core/js-client/src/util/logger.ts b/packages/core/js-client/src/util/logger.ts index 7d8615cd..3878e888 100644 --- a/packages/core/js-client/src/util/logger.ts +++ b/packages/core/js-client/src/util/logger.ts @@ -50,15 +50,3 @@ export function marineLogger(serviceId: string): MarineLogger { info: debug(`${name}:info`), }; } - -export function disable() { - debug.disable(); -} - -export function enable(namespaces: string) { - debug.enable(namespaces); -} - -export function enabled(namespaces: string) { - return debug.enabled(namespaces); -}