Skip to content

Conversation

@wailinkyaww
Copy link

This PR aim to add a documentation on how to initialize the Logging namespace when using ES Module.

ES modules - module system is differ from traditional commonjs.

The key problem is, they hoist all the import statements, then execute the code from the first import first ( from top to bottom ).

This cause the loggers inside imported files to have default namespace other than the one initialized in entry file like index.ts.

I spent a few days debugging on this. Hope this help!

Other Tips:

Pass in the filename explicitly:

import { Log } from 'debug-next'

const { log, logVerbose, ... } = Log(import.meta.filename) // <- for logging inside a file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant