mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-22 20:31:32 +00:00
fix(js-client): Improve logging (#418)
* Improve logging * Improve further connection logs
This commit is contained in:
@ -18,7 +18,7 @@ import { noise } from "@chainsafe/libp2p-noise";
|
|||||||
import { yamux } from "@chainsafe/libp2p-yamux";
|
import { yamux } from "@chainsafe/libp2p-yamux";
|
||||||
import { PeerIdB58 } from "@fluencelabs/interfaces";
|
import { PeerIdB58 } from "@fluencelabs/interfaces";
|
||||||
import { identify } from "@libp2p/identify";
|
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 { peerIdFromString } from "@libp2p/peer-id";
|
||||||
import { ping } from "@libp2p/ping";
|
import { ping } from "@libp2p/ping";
|
||||||
import { webSockets } from "@libp2p/websockets";
|
import { webSockets } from "@libp2p/websockets";
|
||||||
@ -180,33 +180,39 @@ export class RelayConnection implements IConnection {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.trace("sending particle...");
|
|
||||||
|
|
||||||
// Reusing active connection here
|
// Reusing active connection here
|
||||||
const stream = await this.lib2p2Peer.dialProtocol(
|
const stream = await this.lib2p2Peer.dialProtocol(
|
||||||
this.relayAddress,
|
this.relayAddress,
|
||||||
PROTOCOL_NAME,
|
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;
|
const sink = stream.sink;
|
||||||
|
|
||||||
await pipe([fromString(serializeToString(particle))], encode, 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
|
private async processIncomingMessage(msg: string) {
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
|
||||||
private async processIncomingMessage(msg: string, stream: Stream) {
|
|
||||||
let particle: Particle | undefined;
|
let particle: Particle | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
particle = Particle.fromString(msg);
|
particle = Particle.fromString(msg);
|
||||||
|
|
||||||
log.trace(
|
log.trace(
|
||||||
"got particle from stream with id %s and particle id %s",
|
"received particle %s from %s",
|
||||||
stream.id,
|
|
||||||
particle.id,
|
particle.id,
|
||||||
|
this.relayAddress.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const initPeerId = peerIdFromString(particle.initPeerId);
|
const initPeerId = peerIdFromString(particle.initPeerId);
|
||||||
@ -268,7 +274,7 @@ export class RelayConnection implements IConnection {
|
|||||||
async (source) => {
|
async (source) => {
|
||||||
try {
|
try {
|
||||||
for await (const msg of source) {
|
for await (const msg of source) {
|
||||||
await this.processIncomingMessage(msg, stream);
|
await this.processIncomingMessage(msg);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("connection closed: %j", e);
|
log.error("connection closed: %j", e);
|
||||||
|
@ -424,8 +424,13 @@ export abstract class FluencePeer {
|
|||||||
): Promise<CallServiceResult> {
|
): Promise<CallServiceResult> {
|
||||||
const particleId = req.particleContext.particleId;
|
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(
|
log_particle.trace(
|
||||||
"id %s. executing call service handler %j",
|
"id %s. executing call service handler detailed %j",
|
||||||
particleId,
|
particleId,
|
||||||
req,
|
req,
|
||||||
);
|
);
|
||||||
|
@ -50,15 +50,3 @@ export function marineLogger(serviceId: string): MarineLogger {
|
|||||||
info: debug(`${name}:info`),
|
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);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user