*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": {
"@lumeweb/dht-flood": "https://git.lumeweb.com/LumeWeb/dht-flood.git",
"@protobuf-ts/plugin": "^2.8.1",
"@protobuf-ts/runtime": "^2.8.2",
"b4a": "^1.6.1",
"compact-encoding": "^2.11.0",
"hypercore-crypto": "^3.3.0",
@ -13,12 +14,14 @@
"loglevel": "^1.8.1",
"lru": "^3.1.0",
"ordered-json": "^0.1.1",
"pino": "^8.8.0",
"protocol-buffers-encodings": "^1.2.0",
"protomux-rpc": "^1.3.0"
},
"devDependencies": {
"@types/b4a": "^1.6.0",
"@types/debug": "^4.1.7",
"@types/node": "^18.11.17",
"crypto": "^1.0.1",
"debug": "^4.3.4",
"hyperswarm": "^4.3.5",
@ -26,6 +29,7 @@
"protoc": "^1.1.3",
"sodium-universal": "^3.1.0",
"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 type { PartialMessage } from "@protobuf-ts/runtime";
import DHTFlood from "@lumeweb/dht-flood";
import log, { getLogger } from "loglevel";
import type { Logger } from "pino";
type Bootstrap = {
[key: string]: State;
@ -33,18 +33,24 @@ export default class DHTCache extends EventEmitter {
private heartBeatInterval: number;
protected flood: DHTFlood;
private log: log.Logger;
private log: Logger;
constructor(
swarm: any,
{
id = swarm.keyPair.publicKey,
logger,
heartBeatInterval = 60,
...opts
}: { id?: Buffer; [key: string]: any } = {}
}: { id?: Buffer; logger?: Logger; [key: string]: any } = {}
) {
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.bootstrapped = false;
@ -55,7 +61,7 @@ export default class DHTCache extends EventEmitter {
this._online = new Set([this._maybeHexify(this.id)]);
this.swarm = swarm;
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-remove", (peer) => this.removePeerHandler(peer));