*Switch to pino logger

This commit is contained in:
Derrick Hammer 2022-12-19 08:43:17 -05:00
parent ddb360cb8a
commit 67c098cb0d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 16 additions and 6 deletions

View File

@ -6,6 +6,7 @@
"dependencies": { "dependencies": {
"@lumeweb/dht-flood": "https://git.lumeweb.com/LumeWeb/dht-flood.git", "@lumeweb/dht-flood": "https://git.lumeweb.com/LumeWeb/dht-flood.git",
"@protobuf-ts/plugin": "^2.8.1", "@protobuf-ts/plugin": "^2.8.1",
"@protobuf-ts/runtime": "^2.8.2",
"b4a": "^1.6.1", "b4a": "^1.6.1",
"compact-encoding": "^2.11.0", "compact-encoding": "^2.11.0",
"hypercore-crypto": "^3.3.0", "hypercore-crypto": "^3.3.0",
@ -13,12 +14,14 @@
"loglevel": "^1.8.1", "loglevel": "^1.8.1",
"lru": "^3.1.0", "lru": "^3.1.0",
"ordered-json": "^0.1.1", "ordered-json": "^0.1.1",
"pino": "^8.8.0",
"protocol-buffers-encodings": "^1.2.0", "protocol-buffers-encodings": "^1.2.0",
"protomux-rpc": "^1.3.0" "protomux-rpc": "^1.3.0"
}, },
"devDependencies": { "devDependencies": {
"@types/b4a": "^1.6.0", "@types/b4a": "^1.6.0",
"@types/debug": "^4.1.7", "@types/debug": "^4.1.7",
"@types/node": "^18.11.17",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"hyperswarm": "^4.3.5", "hyperswarm": "^4.3.5",
@ -26,6 +29,7 @@
"protoc": "^1.1.3", "protoc": "^1.1.3",
"sodium-universal": "^3.1.0", "sodium-universal": "^3.1.0",
"tape": "^5.6.1", "tape": "^5.6.1",
"ts-proto": "^1.131.2" "ts-proto": "^1.131.2",
"typescript": "^4.9.4"
} }
} }

View File

@ -11,7 +11,7 @@ import { Message, State, Type } from "./messages.js";
import sodium from "sodium-universal"; import sodium from "sodium-universal";
import type { PartialMessage } from "@protobuf-ts/runtime"; import type { PartialMessage } from "@protobuf-ts/runtime";
import DHTFlood from "@lumeweb/dht-flood"; import DHTFlood from "@lumeweb/dht-flood";
import log, { getLogger } from "loglevel"; import type { Logger } from "pino";
type Bootstrap = { type Bootstrap = {
[key: string]: State; [key: string]: State;
@ -33,18 +33,24 @@ export default class DHTCache extends EventEmitter {
private heartBeatInterval: number; private heartBeatInterval: number;
protected flood: DHTFlood; protected flood: DHTFlood;
private log: log.Logger; private log: Logger;
constructor( constructor(
swarm: any, swarm: any,
{ {
id = swarm.keyPair.publicKey, id = swarm.keyPair.publicKey,
logger,
heartBeatInterval = 60, heartBeatInterval = 60,
...opts ...opts
}: { id?: Buffer; [key: string]: any } = {} }: { id?: Buffer; logger?: Logger; [key: string]: any } = {}
) { ) {
super(); super();
if (!id) throw new TypeError("Must provide id for self"); if (!id) {
throw new TypeError("Must provide id for self");
}
if (!logger) {
throw new TypeError("Must logger for self");
}
this.id = b4a.from(id) as Buffer; this.id = b4a.from(id) as Buffer;
this.bootstrapped = false; this.bootstrapped = false;
@ -55,7 +61,7 @@ export default class DHTCache extends EventEmitter {
this._online = new Set([this._maybeHexify(this.id)]); this._online = new Set([this._maybeHexify(this.id)]);
this.swarm = swarm; this.swarm = swarm;
this.flood = new DHTFlood({ id, swarm, ...opts }); this.flood = new DHTFlood({ id, swarm, ...opts });
this.log = getLogger("dht-cache"); this.log = logger;
this.flood.on("peer-open", (peer) => this.addPeerHandler(peer)); this.flood.on("peer-open", (peer) => this.addPeerHandler(peer));
this.flood.on("peer-remove", (peer) => this.removePeerHandler(peer)); this.flood.on("peer-remove", (peer) => this.removePeerHandler(peer));