@offirmo/universal-debug-api-browser
v1.0.1
Published
An implementation of the universal debug API for browsers
Downloads
7
Readme
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.