jizy-logger
v2.1.6
Published
A simple JS logger.
Downloads
427
Readme
jizy-logger
A thin wrapper around window.console that gives you an on/off switch, level gating, safe JSON cloning, and a small fallback to console.dir for non-serializable values.
Features
- One togglable instance — flip
setActive(true)to enable, leave it off in production. - Routes to the matching
consolemethod (log,info,warn,error,debug,dir). - Optional label:
log('label', value)printslabel :,value. - Deep-clones values through
JSON.parse(JSON.stringify(...))so what you log is what you had at call time. - Falls back to
console.dirwhen a value can't be serialized (circular refs, etc.). - Compatibility aliases:
warning()→warn,add()→log.
Install
npm install jizy-loggerUsage
import jLogger from 'jizy-logger';
const log = new jLogger(true); // active
log.log('hello'); // console.log('hello')
log.info('user', { id: 42 }); // console.info('user : ', { id: 42 })
log.warn('careful'); // console.warn('careful')
log.error('boom'); // console.error('boom')
log.dir(domNode); // console.dir(domNode) — no JSON clone
const a = {}; a.self = a;
log.log(a); // falls back to console.dir(a)
log.setActive(false); // silences everything except clear()
log.clear(); // console.clear()API
Constructor
new jLogger(active = false, level = 0)
active:trueto emit logs,falseto silence.level: integer, stored on the instance for caller-side gating.
Methods
setActive(active = false)— chainable.setLevel(level = 0)— chainable.status()—trueifconsoleis available and the logger is active.clear()— callsconsole.clear()(only gated on availability, not onactive).log(...),info(...),warn(...),error(...),debug(...),dir(...)warning(...)— alias forwarn.add(...)— alias forlog.
Argument shapes
Each logging method accepts:
(value)— prints just the value.(label, value)— printslabel + ' : 'then the value.(label, value, level)— same, with a level hint stored on the parsed args (not currently used for filtering).
Calling with no arguments emits console.log('Invalid arguments', args) and produces no further output.
Tests
npm testJest (ESM mode via --experimental-vm-modules) covers constructor defaults, chainable setters, output routing, JSON cloning, circular-ref fallback, compatibility aliases, and the inactive-logger contract.
License
MIT — see LICENSE.
