# limit-logger

> A tiny TypeScript library that lets you put limits on how frequently console.log is called. Useful for debugging animation loops.

Latest version **1.0.2** (published 2022-06-21) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install limit-logger
pnpm add limit-logger
yarn add limit-logger
bun add limit-logger
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-06-21 |
| First published | 2022-06-21 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jlivak |
| Maintainers | jlivak |
| Keywords | console, log, warning, error, limit, logger, canvas, animation, debug, info |

## Links

- npm: https://www.npmjs.com/package/limit-logger
- Repository: https://github.com/jlivak/limit-logger
- Homepage: https://github.com/jlivak/limit-logger#readme
- Issues: https://github.com/jlivak/limit-logger/issues
- npm.io page: https://npm.io/package/limit-logger

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-06-21
- 1.0.1 — 2022-06-21

## README

# Limit Logger (limit-logger)

[![License](https://img.shields.io/github/license/jlivak/limit-logger)](https://github.com/jlivak/limit-logger/blob/master/LICENSE) [![NPM Version](https://img.shields.io/npm/v/limit-logger)](https://npmjs.com/package/limit-logger)

Limit Logger is a small library that exposes common console logging functions with an added minimum frequency parameter.  Subsequent calls that happen before the given frequency is elapsed are discarded.  This allows you to avoid flooding the console with logging statements.

The main inspiration for writing this is while working with 2D/3D canvas rendering and animation loops (for ex. with `Window.requestAnimationFrame()`) and wanting to log debug output, but only needing it once every second and not once every frame.

## Usage

Limit Logger exposes a single `LimitLogger` export, on which you can call the following logger functions.

Each call must be given a `logId` (a unique string used for tracking subsequent calls) and a `minimumFrequencyInSeconds` (the minimum number of seconds that must pass before outputting another message with the same `logId`, fractional values are supported).

### Debug

```ts
// Log the debug message "I'm a debug message!" no more than once every 5 seconds.
LimitLogger.debug(`I'm a debug message!`, `Debug1`, 5);
```
### Info
```ts
// Log the `SomeObject` object no more than once every 250 milliseconds.
LimitLogger.info(SomeObject, `Info`, .25);
```

### Log
```ts
// Log the "Testing" log message no more than once every second.
LimitLogger.log(`Testing`, `Debug1`, 1);
```

### Warn
```ts
// Log the "Warning" log message no more than once five seconds.
LimitLogger.warn(`Warning`, `Manager.js:52`, 5);
```

### Error
```ts
// Log a blank error no more than once every minute.
LimitLogger.error(new Error(), `Error1`, 60);
```

### Advanced Usages
```ts
// Log only one message with the `Log.ts` id every minute.
// The first subsequent call after 60 seconds will be outputted.
LimitLogger.log("An output message", `Log.ts`, 60);
...
LimitLogger.log("An different output message", `Log.ts`, 60);
```

```ts
// Log the first message only once every minute.
// However allow the second message to be written after only 15 seconds have elapsed.
LimitLogger.error("Something bad happened.", `Error`, 60);
...
LimitLogger.error("Something really bad happened!", `Error`, 15);
```

---
_Source: https://npm.io/package/limit-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
