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

1.0.1 • Public • Published

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

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

This is the browser implementation of Offirmo’s Universal Debug API.

Usage

The Universal Debug API is exposed as expected:

import {
	getLogger,
	overrideHook,
} from '@offirmo/universal-debug-api-browser'

const logger = getLogger({ name: 'foo', suggestedLevel: 'info' })
logger.silly('Hello')
logger.verbose('Hello')
logger.fatal('Hello')

const SERVER_URL = overrideHook('server-url', 'https://prod.dev')
logger.info('Server URL=', {SERVER_URL})

Specific to the browser version, overrides are set through local storage:

localStorage.setItem('🛠UDA.override.logger.foo.logLevel', '"verbose"')
localStorage.setItem('🛠UDA.override.server-url', '"https://prod.dev"')
// loglevel || ll => log level
// cohort || co => experiment cohort
// is has should was will => boolean

Don't forget that overrides accept only JSON!

Debug:

localStorage.setItem('🛠UDA.override.logger._UDA_internal.logLevel', '"silly"')

Notes

Why would I use a mechanism such as overrideHook() when I can simply read local storage?

Sure you can if your code is browser only. The point of the Universal Debug API is to be isomorphic, for shared code.

For ex. the same code running on node will get its overrides from ENV vars.

/@offirmo/universal-debug-api-browser/

    Package Sidebar

    Install

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

    Weekly Downloads

    0

    Version

    1.0.1

    License

    Unlicense

    Unpacked Size

    77.4 kB

    Total Files

    32

    Last publish

    Collaborators

    • offirmo