Skip to content

Commit

Permalink
fix(@libp2p/webrtc): use stream logger instead of global logger (#2042)
Browse files Browse the repository at this point in the history
Streams should use the `this.log` property for logging to ensure
the log messages are scoped to an invidual stream.
  • Loading branch information
achingbrain authored Sep 12, 2023
1 parent cf13a5b commit 88c47f5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/transport-webrtc/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { Uint8ArrayList } from 'uint8arraylist'
import { Message } from './pb/message.js'
import type { Direction } from '@libp2p/interface/connection'

const log = logger('libp2p:webrtc:stream')

export interface DataChannelOpts {
maxMessageSize: number
maxBufferedAmount: number
Expand Down Expand Up @@ -92,7 +90,7 @@ export class WebRTCStream extends AbstractStream {
break

default:
log.error('unknown datachannel state %s', this.channel.readyState)
this.log.error('unknown datachannel state %s', this.channel.readyState)
throw new CodeError('Unknown datachannel state', 'ERR_INVALID_STATE')
}

Expand All @@ -112,7 +110,7 @@ export class WebRTCStream extends AbstractStream {

this.channel.onclose = (_evt) => {
void this.close().catch(err => {
log.error('error closing stream after channel closed', err)
this.log.error('error closing stream after channel closed', err)
})
}

Expand Down Expand Up @@ -145,7 +143,7 @@ export class WebRTCStream extends AbstractStream {
}
})
.catch(err => {
log.error('error processing incoming data channel messages', err)
this.log.error('error processing incoming data channel messages', err)
})
}

Expand Down Expand Up @@ -183,7 +181,7 @@ export class WebRTCStream extends AbstractStream {

this.messageQueue.append(data)
} else {
log.error('unknown datachannel state %s', this.channel.readyState)
this.log.error('unknown datachannel state %s', this.channel.readyState)
throw new CodeError('Unknown datachannel state', 'ERR_INVALID_STATE')
}
}
Expand Down Expand Up @@ -242,7 +240,7 @@ export class WebRTCStream extends AbstractStream {
}

private async _sendFlag (flag: Message.Flag): Promise<void> {
log.trace('Sending flag: %s', flag.toString())
this.log.trace('Sending flag: %s', flag.toString())
const msgbuf = Message.encode({ flag })
const prefixedBuf = lengthPrefixed.encode.single(msgbuf)

Expand Down

0 comments on commit 88c47f5

Please sign in to comment.