Skip to content

Commit

Permalink
fix: service worker logs are visible again (#395)
Browse files Browse the repository at this point in the history
* fix: service worker logs are visible again

* chore: self pr suggestion
  • Loading branch information
SgtPooki authored Oct 22, 2024
1 parent 2b26bd6 commit 98659e2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { prefixLogger, type ComponentLogger } from '@libp2p/logger'
import { type ComponentLogger, type Logger } from '@libp2p/logger'
import debug from 'debug'

/**
* Hack to get around @libp2p/logger not working inside a service worker.
*/
const createlibp2pLogger = (prefix: string): Logger => {
const mainLogger = debug(prefix)
return Object.assign(debug(prefix), {
error: mainLogger.extend('error'),
trace: mainLogger.extend('trace')
})
}
export function prefixLogger (prefix: string): ComponentLogger {
return {
forComponent (name: string) {
return createlibp2pLogger(`${prefix}:${name}`)
}
}
}
const host = globalThis.location.host.replace(':', '_')

const swLogPrefix = `helia:sw-gateway:sw:${host}`
Expand Down

0 comments on commit 98659e2

Please sign in to comment.