Skip to content

Commit 5696e3b

Browse files
author
Akim
authored
fix(js-client): Improve logging (#418)
* Improve logging * Improve further connection logs
1 parent 15f96dc commit 5696e3b

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

packages/core/js-client/src/connection/RelayConnection.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { noise } from "@chainsafe/libp2p-noise";
1818
import { yamux } from "@chainsafe/libp2p-yamux";
1919
import { PeerIdB58 } from "@fluencelabs/interfaces";
2020
import { identify } from "@libp2p/identify";
21-
import type { PeerId, Stream } from "@libp2p/interface";
21+
import type { PeerId } from "@libp2p/interface";
2222
import { peerIdFromString } from "@libp2p/peer-id";
2323
import { ping } from "@libp2p/ping";
2424
import { webSockets } from "@libp2p/websockets";
@@ -180,33 +180,39 @@ export class RelayConnection implements IConnection {
180180
);
181181
}
182182

183-
log.trace("sending particle...");
184-
185183
// Reusing active connection here
186184
const stream = await this.lib2p2Peer.dialProtocol(
187185
this.relayAddress,
188186
PROTOCOL_NAME,
189187
);
190188

191-
log.trace("created stream with id ", stream.id);
189+
log.trace(
190+
"sending particle %s to %s",
191+
particle.id,
192+
this.relayAddress.toString(),
193+
);
194+
192195
const sink = stream.sink;
193196

194197
await pipe([fromString(serializeToString(particle))], encode, sink);
195-
log.trace("data written to sink");
198+
199+
log.trace(
200+
"particle %s sent to %s",
201+
particle.id,
202+
this.relayAddress.toString(),
203+
);
196204
}
197205

198-
// Await will appear after uncommenting lines in func body
199-
// eslint-disable-next-line @typescript-eslint/require-await
200-
private async processIncomingMessage(msg: string, stream: Stream) {
206+
private async processIncomingMessage(msg: string) {
201207
let particle: Particle | undefined;
202208

203209
try {
204210
particle = Particle.fromString(msg);
205211

206212
log.trace(
207-
"got particle from stream with id %s and particle id %s",
208-
stream.id,
213+
"received particle %s from %s",
209214
particle.id,
215+
this.relayAddress.toString(),
210216
);
211217

212218
const initPeerId = peerIdFromString(particle.initPeerId);
@@ -268,7 +274,7 @@ export class RelayConnection implements IConnection {
268274
async (source) => {
269275
try {
270276
for await (const msg of source) {
271-
await this.processIncomingMessage(msg, stream);
277+
await this.processIncomingMessage(msg);
272278
}
273279
} catch (e) {
274280
log.error("connection closed: %j", e);

packages/core/js-client/src/jsPeer/FluencePeer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,13 @@ export abstract class FluencePeer {
424424
): Promise<CallServiceResult> {
425425
const particleId = req.particleContext.particleId;
426426

427+
log_particle.debug("id %s. executing call service handler %j", particleId, {
428+
serviceId: req.serviceId,
429+
functionName: req.fnName,
430+
});
431+
427432
log_particle.trace(
428-
"id %s. executing call service handler %j",
433+
"id %s. executing call service handler detailed %j",
429434
particleId,
430435
req,
431436
);

packages/core/js-client/src/util/logger.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,3 @@ export function marineLogger(serviceId: string): MarineLogger {
5050
info: debug(`${name}:info`),
5151
};
5252
}
53-
54-
export function disable() {
55-
debug.disable();
56-
}
57-
58-
export function enable(namespaces: string) {
59-
debug.enable(namespaces);
60-
}
61-
62-
export function enabled(namespaces: string) {
63-
return debug.enabled(namespaces);
64-
}

0 commit comments

Comments
 (0)