Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"@libp2p/peer-id": "^2.0.3",
"@types/debug": "^4.1.7",
"aegir": "^38.1.7",
"sinon": "^15.1.0",
"uint8arrays": "^4.0.3"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ debug.formatters.k = (v: Key): string => {
}

// Add a formatter for stringifying Multiaddrs
debug.formatters.ma = (v?: Multiaddr): string => {
debug.formatters.a = (v?: Multiaddr): string => {
return v == null ? 'undefined' : v.toString()
}

Expand Down
18 changes: 16 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { base58btc } from 'multiformats/bases/base58'
import { base32 } from 'multiformats/bases/base32'
import { base64 } from 'multiformats/bases/base64'
import { Key } from 'interface-datastore'
import sinon from 'sinon'

describe('logger', () => {
it('creates a logger', () => {
Expand Down Expand Up @@ -70,13 +71,26 @@ describe('logger', () => {
expect(debug.formatters).to.have.property('p').that.is.a('function')
expect(debug.formatters).to.have.property('c').that.is.a('function')
expect(debug.formatters).to.have.property('k').that.is.a('function')
expect(debug.formatters).to.have.property('ma').that.is.a('function')
expect(debug.formatters).to.have.property('a').that.is.a('function')
})

it('test printf style formatting', () => {
const log = logger('printf-style')
debug.enable('printf-style')

const ma = multiaddr('/ip4/127.0.0.1/tcp/4001')

const debugSpy = sinon.spy(debug, 'log')

log('multiaddr %a', ma)

expect(debugSpy.firstCall.args[0], 'Multiaddr formatting not included').to.include(`multiaddr ${ma.toString()}`)
})

it('test ma formatter', () => {
const ma = multiaddr('/ip4/127.0.0.1/tcp/4001')

expect(debug.formatters.ma(ma)).to.equal(ma.toString())
expect(debug.formatters.a(ma)).to.equal(ma.toString())
})

it('test peerId formatter', () => {
Expand Down