fix(js-client): Improve logging (#418)

* Improve logging

* Improve further connection logs
This commit is contained in:
Akim 2024-01-17 18:30:10 +07:00 committed by GitHub
parent 15f96dc5f7
commit 5696e3beba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 24 deletions

View File

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

View File

@ -424,8 +424,13 @@ export abstract class FluencePeer {
): Promise<CallServiceResult> {
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,
);

View File

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