@offirmo/universal-debug-api-node
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Offirmo’s Universal Debug API - node implementation
Offirmo’s quality seal

npm badge dependencies badge bundle size badge license badge maintenance status badge

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:

  1. to upper case
  2. 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.

Readme

Keywords

Package Sidebar

Install

npm i @offirmo/universal-debug-api-node

Weekly Downloads

0

Version

0.2.0

License

Unlicense

Unpacked Size

48.1 kB

Total Files

31

Last publish

Collaborators

  • offirmo