libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.github.io/js-libp2p/
Other
2.34k stars 447 forks source link

bug: @libp2p/logger doesn't work in service workers #2778

Closed SgtPooki closed 1 month ago

SgtPooki commented 1 month ago

When attempting to use @libp2p/logger in the service-worker gateway, logs generated by the service worker were not being logged until I explicitly overrode the @libp2p/logger's forComponent and prefixLogger functions.

see https://github.com/ipfs/service-worker-gateway/pull/395

Repro repo at https://github.com/SgtPooki/libp2p-logger-bug-repro

achingbrain commented 1 month ago

You need to import enable from @libp2p/logger and not debug.

Part of the point of wrapping debug with @libp2p/logger is that it allows us to swap out the underlying log implementation without having to change any calling code which is what happened in #2648 - calling through to the underlying implementation directly defeats the whole purpose.

SgtPooki commented 1 month ago

using enable from @libp2p/logger works, thanks