Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 184ef21

Browse files
authored
fix: use trace logging for happy paths (#59)
1 parent 647568f commit 184ef21

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/handle.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ export async function handle (stream: Duplex<any>, protocols: string | string[],
6363

6464
while (true) {
6565
const protocol = await multistream.readString(reader, options)
66-
log('read "%s"', protocol)
66+
log.trace('read "%s"', protocol)
6767

6868
if (protocol === PROTOCOL_ID) {
69-
log('respond with "%s" for "%s"', PROTOCOL_ID, protocol)
69+
log.trace('respond with "%s" for "%s"', PROTOCOL_ID, protocol)
7070
multistream.write(writer, uint8ArrayFromString(PROTOCOL_ID), options)
7171
continue
7272
}
7373

7474
if (protocols.includes(protocol)) {
7575
multistream.write(writer, uint8ArrayFromString(protocol), options)
76-
log('respond with "%s" for "%s"', protocol, protocol)
76+
log.trace('respond with "%s" for "%s"', protocol, protocol)
7777
rest()
7878
return { stream: shakeStream, protocol }
7979
}
@@ -82,7 +82,7 @@ export async function handle (stream: Duplex<any>, protocols: string | string[],
8282
// <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n\n
8383
multistream.write(writer, new Uint8ArrayList(...protocols.map(p => multistream.encode(uint8ArrayFromString(p)))), options)
8484
// multistream.writeAll(writer, protocols.map(p => uint8ArrayFromString(p)))
85-
log('respond with "%s" for %s', protocols, protocol)
85+
log.trace('respond with "%s" for %s', protocols, protocol)
8686
continue
8787
}
8888

src/select.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ export async function select (stream: Duplex<any>, protocols: string | string[],
6868
throw new Error('At least one protocol must be specified')
6969
}
7070

71-
log('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
71+
log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
7272
const p1 = uint8ArrayFromString(PROTOCOL_ID)
7373
const p2 = uint8ArrayFromString(protocol)
7474
multistream.writeAll(writer, [p1, p2], options)
7575

7676
let response = await multistream.readString(reader, options)
77-
log('select: read "%s"', response)
77+
log.trace('select: read "%s"', response)
7878

7979
// Read the protocol response if we got the protocolId in return
8080
if (response === PROTOCOL_ID) {
8181
response = await multistream.readString(reader, options)
82-
log('select: read "%s"', response)
82+
log.trace('select: read "%s"', response)
8383
}
8484

8585
// We're done
@@ -90,10 +90,10 @@ export async function select (stream: Duplex<any>, protocols: string | string[],
9090

9191
// We haven't gotten a valid ack, try the other protocols
9292
for (const protocol of protocols) {
93-
log('select: write "%s"', protocol)
93+
log.trace('select: write "%s"', protocol)
9494
multistream.write(writer, uint8ArrayFromString(protocol), options)
9595
const response = await multistream.readString(reader, options)
96-
log('select: read "%s" for "%s"', response, protocol)
96+
log.trace('select: read "%s" for "%s"', response, protocol)
9797

9898
if (response === protocol) {
9999
rest() // End our writer so others can start writing to stream

0 commit comments

Comments
 (0)