# iflog

<a aria-label="License" href="https://opensource.org/licenses/MIT"><img alt="" src="https://img.shields.io/npm/l/turbo.svg?style=for-the-badge&labelColor=000000&color="></a>
<a aria-label="NPM version" href="https://npmjs.com/package/iflog"><img src="https://img.shields.io/npm/v/iflog.svg?style=for-the-badge&labelColor=000000"/></a>
<a href="https://www.npmjs.com/package/iflog"><img src="https://img.shields.io/npm/d18m/iflog?style=for-the-badge&labelColor=000000"></a>

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!**

## Installation

```bash
npm i iflog
```

## Usage

```js
import 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)
```

## Production Debugging

Need to debug logs in production? You have two options:

### 1. URL Parameter Override

Simply add `?iflog=true` to your URL:

```
https://yoursite.com/page?iflog=true
```

### 2. Manual Enable/Disable

Use the `enable()` and `disable()` methods for programmatic control:

```js
iflog.enable(); // Force logging on
iflog.log("This will show even in production");
iflog.disable(); // Force logging off
```

Both 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.

## How it works

All methods are no-ops in production (`process.env.NODE_ENV === 'production'`), except when:

- The URL parameter `?iflog=true` is present, OR
- `iflog.enable()` has been called

In development, they proxy to the corresponding `console` methods, unless `iflog.disable()` has been called.

## API

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)`

### Control Methods

- `iflog.enable()` - Force enable logging regardless of environment
- `iflog.disable()` - Force disable logging regardless of environment
- `iflog.toggle()` - Toggle between enabled and disabled states
- `iflog.isEnabled()` - Returns `true` if logging is enabled, `false` otherwise
- `iflog.reset()` - Reset to default behavior

## License

MIT
