A conditional console utility that only logs in development mode. It wraps all standard console methods and only outputs when process.env.NODE_ENV !== 'production'. Now with URL parameter override and manual controls for production debugging!
npm i iflogimport iflog from "iflog";
iflog.log("This will only log in development!");
iflog.error("This error will only show in development!");
iflog.table([{ a: 1 }, { a: 2 }]);
if (iflog.isEnabled()) {
// do something only when logging is enabled
}
// Manual control
iflog.enable(); // Force enable logging (even in production)
iflog.disable(); // Force disable logging (even in development)Need to debug logs in production? You have two options:
Simply add ?iflog=true to your URL:
https://yoursite.com/page?iflog=true
Use the enable() and disable() methods for programmatic control:
iflog.enable(); // Force logging on
iflog.log("This will show even in production");
iflog.disable(); // Force logging offBoth methods will override the environment detection and give you full control over iflog's behavior. This enables you to add keyboard shortcuts to toggle logging in production or bind to a button in your app.
All methods are no-ops in production (process.env.NODE_ENV === 'production'), except when:
- The URL parameter
?iflog=trueis present, OR iflog.enable()has been called
In development, they proxy to the corresponding console methods, unless iflog.disable() has been called.
All methods below only output when iflog is enabled (development mode, URL override, or manually enabled):
iflog.assert(condition, ...args)iflog.clear()iflog.count(label)iflog.countReset(label)iflog.debug(...args)iflog.dir(...args)iflog.dirxml(...args)iflog.error(...args)iflog.exception(...args)(alias for error)iflog.group(...args)iflog.groupCollapsed(...args)iflog.groupEnd()iflog.info(...args)iflog.log(...args)iflog.profile(label)iflog.profileEnd(label)iflog.table(tabularData, properties)iflog.time(label)iflog.timeEnd(label)iflog.timeLog(label, ...args)iflog.timeStamp(label)iflog.trace(...args)iflog.warn(...args)
iflog.enable()- Force enable logging regardless of environmentiflog.disable()- Force disable logging regardless of environmentiflog.toggle()- Toggle between enabled and disabled statesiflog.isEnabled()- Returnstrueif logging is enabled,falseotherwiseiflog.reset()- Reset to default behavior
MIT