Skip to content

Commit

Permalink
Revert "feat: logging improvement (#102)"
Browse files Browse the repository at this point in the history
This reverts commit 94ec5ef.
  • Loading branch information
d-roak authored Aug 21, 2024
1 parent a5af72d commit 15d6a76
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 166 deletions.
3 changes: 1 addition & 2 deletions packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@libp2p/webtransport": "^4.1.2",
"@multiformats/multiaddr": "^12.3.0",
"it-pipe": "^3.0.1",
"libp2p": "^1.8.3",
"tslog": "^4.9.3"
"libp2p": "^1.8.3"
}
}
58 changes: 36 additions & 22 deletions packages/network/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ import { bootstrap } from "@libp2p/bootstrap";
import { webTransport } from "@libp2p/webtransport";
import { autoNAT } from "@libp2p/autonat";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
import { Logger, ILogObj, ISettingsParam } from "tslog";

let log: Logger<ILogObj> = new Logger();

// snake_casing to match the JSON config
export interface TopologyNetworkNodeConfig {
addresses?: string[];
bootstrap?: boolean;
bootstrap_peers?: string[];
private_key_seed?: string;
tslog_config?: ISettingsParam<ILogObj>;
}

export class TopologyNetworkNode {
Expand All @@ -46,8 +42,6 @@ export class TopologyNetworkNode {

constructor(config?: TopologyNetworkNodeConfig) {
this._config = config;
log = new Logger(config?.tslog_config);
log.settings.name = "topology::network";
}

async start() {
Expand Down Expand Up @@ -121,47 +115,60 @@ export class TopologyNetworkNode {
this._pubsub = this._node.services.pubsub as PubSub<GossipsubEvents>;
this.peerId = this._node.peerId.toString();

log.info("::start", "Successfuly started topology network w/ peer_id", this.peerId);
console.log(
"topology::network::start: Successfuly started topology network w/ peer_id",
this.peerId,
);

// TODO remove this or add better logger
// we need to keep it now for debugging
this._node.addEventListener("peer:connect", (e) =>
log.info("::start::peer::connect", e.detail)
console.log("peer:connect", e.detail),
);
this._node.addEventListener("peer:discovery", (e) =>
log.info("::start::peer::discovery", e.detail)
console.log("peer:discovery", e.detail),
);
this._node.addEventListener("peer:identify", (e) =>
log.info("::start::peer::identify", e.detail)
console.log("peer:identify", e.detail),
);
}

subscribe(topic: string) {
if (!this._node) {
log.error("::subscribe", "Node not initialized, please run .start()");
console.error(
"topology::network::subscribe: Node not initialized, please run .start()",
);
return;
}

try {
this._pubsub?.subscribe(topic);
this._pubsub?.getPeers();
log.info("::subscribe", "Successfuly subscribed the topic", topic);
console.log(
"topology::network::subscribe: Successfuly subscribed the topic",
topic,
);
} catch (e) {
log.error("::subscribe", e);
console.error("topology::network::subscribe:", e);
}
}

unsubscribe(topic: string) {
if (!this._node) {
log.error("::unsubscribe", "Node not initialized, please run .start()");
console.error(
"topology::network::unsubscribe: Node not initialized, please run .start()",
);
return;
}

try {
this._pubsub?.unsubscribe(topic);
log.info("::unsubscribe", "Successfuly unsubscribed the topic", topic);
console.log(
"topology::network::unsubscribe: Successfuly unsubscribed the topic",
topic,
);
} catch (e) {
log.error("::unsubscribe", e);
console.error("topology::network::unsubscribe:", e);
}
}

Expand All @@ -182,9 +189,12 @@ export class TopologyNetworkNode {
if (this._pubsub?.getSubscribers(topic)?.length === 0) return;
await this._pubsub?.publish(topic, message);

log.info("::broadcastMessage", "Successfuly broadcasted message to topic", topic);
console.log(
"topology::network::broadcastMessage: Successfuly broadcasted message to topic",
topic,
);
} catch (e) {
log.error("::sendMessage", e);
console.error("topology::network::broadcastMessage:", e);
}
}

Expand All @@ -194,9 +204,11 @@ export class TopologyNetworkNode {
const stream = <Stream>await connection?.newStream(protocols);
stringToStream(stream, message);

log.info("::sendMessage", "Successfuly sent message to peer", peerId);
console.log(
`topology::network::sendMessage: Successfuly sent message to peer: ${peerId} with message: ${message}`,
);
} catch (e) {
log.error("::sendMessage", e);
console.error("topology::network::sendMessage:", e);
}
}

Expand All @@ -214,9 +226,11 @@ export class TopologyNetworkNode {
const stream: Stream = (await connection?.newStream(protocols)) as Stream;
stringToStream(stream, message);

log.info("::sendGroupMessageRandomPeer", `Successfuly sent message to peer: ${peerId} with message: ${message}`);
console.log(
`topology::network::sendMessageRandomTopicPeer: Successfuly sent message to peer: ${peerId} with message: ${message}`,
);
} catch (e) {
log.error("::sendGroupMessageRandomPeer", e);
console.error("topology::network::sendMessageRandomTopicPeer:", e);
}
}

Expand Down
5 changes: 0 additions & 5 deletions packages/node/configs/bootstrap.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@
"/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP"
],
"private_key_seed": "bootstrap"
},
"tslog_config": {
"minLevel": 3,
"type": "hidden",
"hideLogPositionForProduction": true
}
}
112 changes: 0 additions & 112 deletions packages/node/configs/example.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/node/configs/node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
"/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ"
],
"private_key_seed": "node"
},
"tslog_config": {
"minLevel": 3,
"type": "hidden",
"hideLogPositionForProduction": true
}
}
3 changes: 1 addition & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@topology-foundation/crdt": "0.0.23-5",
"@topology-foundation/network": "0.0.23-5",
"@topology-foundation/object": "0.0.23-5",
"commander": "^12.1.0",
"tslog": "^4.9.3"
"commander": "^12.1.0"
}
}
16 changes: 1 addition & 15 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import { TopologyObjectStore, TopologyObjectStoreCallback } from "./store";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
import { OPERATIONS } from "./operations.js";
import { ILogObj, ISettingsParam } from "tslog"

export * from "./operations.js";

// snake_casing to match the JSON config
export interface TopologyNodeConfig {
network_config?: TopologyNetworkNodeConfig;
tslog_config?: ISettingsParam<ILogObj>;
}

export class TopologyNode {
Expand All @@ -28,19 +26,7 @@ export class TopologyNode {

constructor(config?: TopologyNodeConfig) {
this._config = config;
if(!this._config) this._config = {};
if(!this._config?.tslog_config){
this._config.tslog_config = {
type: "hidden",
minLevel: 3,
hideLogPositionForProduction: true,
prettyLogTemplate: "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{name}}"
};
}
if(!this._config.network_config?.tslog_config){
this._config.network_config = { tslog_config: this._config?.tslog_config };
}
this.networkNode = new TopologyNetworkNode(this._config?.network_config);
this.networkNode = new TopologyNetworkNode(config?.network_config);
this._objectStore = new TopologyObjectStore();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.0.23-5";
export const VERSION = "0.0.22";
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"skipLibCheck": true,
"stripInternal": true,
"resolveJsonModule": true,
"inlineSourceMap": true
"resolveJsonModule": true
}
}

0 comments on commit 15d6a76

Please sign in to comment.