@offirmo/universal-debug-api-node
v0.2.0
Published
Implementation of Offirmo’s Universal Debug Api for node
Downloads
5
Readme
This is the node implementation of Offirmo’s Universal Debug API.
Usage
The Universal Debug API is exposed as expected:
import {
getLogger,
overrideHook,
} from '@offirmo/universal-debug-api-node'
const logger = getLogger({ name: 'foo', suggestedLevel: 'info' })
logger.silly('Hello')
logger.verbose('Hello')
logger.fatal('Hello')
const DB_URL = overrideHook('db-url', 'https://prod.dev')
logger.info('DB URL=', {DB_URL})
Specific to the node version, overrides are set through ENV vars:
UDA_OVERRIDE__LOGGER_FOO_LOGLEVEL=verbose \
UDA_OVERRIDE__DB_URL=localhost:1234 \
node ./doc/demo.js
Because ENV vars format is restricted, keys are automatically normalized:
- to upper case
- separators chars
-.⋄∙ꘌꓺː
are converted to '_'
Though overrides values accept JSON (correctly escaped), as a convenience because escaping is hard in shell and text files, numbers are auto-converted and non-JSON values are defaulted to strings:
UDA_OVERRIDE__LOGGER_FOO_LOGLEVEL=\"verbose\" \
## is equivalent to
UDA_OVERRIDE__LOGGER_FOO_LOGLEVEL=verbose \
Notes
Why would I use a mechanism such as
overrideHook()
when I can simply read ENV vars?
Sure you can if your code is node only. The point of the Universal Debug API is to be isomorphic, for shared code.
For ex. the same code running on a browser could get its overrides from local storage.