# debug-logfmt

> Drop-in debug logger that emits logfmt key=value lines for structured Heroku-style logs.

Latest version **1.4.15** (published 2026-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install debug-logfmt
pnpm add debug-logfmt
yarn add debug-logfmt
bun add debug-logfmt
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.4.15 |
| Published | 2026-08-03 |
| First published | 2019-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 8 |
| Dependencies | 3 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Kiko Beats |
| Maintainers | kikobeats |
| Keywords | bunyan, debug, format, heroku, key-value, logfmt, logger, logging, structured, winston |

## Links

- npm: https://www.npmjs.com/package/debug-logfmt
- Repository: https://github.com/Kikobeats/debug-logfmt
- Issues: https://github.com/Kikobeats/debug-logfmt/issues
- npm.io page: https://npm.io/package/debug-logfmt

## Dependencies (3)

- [pretty-ms](https://npm.io/package/pretty-ms.md) ~7.0.1
- [@kikobeats/time-span](https://npm.io/package/@kikobeats/time-span.md) ~1.0.5
- [null-prototype-object](https://npm.io/package/null-prototype-object.md) ~1.2.2

## 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.4.15 (latest) — 2026-08-03
- 1.4.14 — 2026-07-30
- 1.4.13 — 2026-06-19
- 1.4.12 — 2026-06-02
- 1.4.11 — 2026-04-13
- 1.4.10 — 2026-03-26
- 1.4.9 — 2026-03-18
- 1.4.8 — 2026-02-27
- 1.4.7 — 2025-11-21
- 1.4.6 — 2025-10-14
- 1.4.5 — 2025-09-09
- 1.4.4 — 2025-09-09
- 1.4.3 — 2025-09-06
- 1.4.2 — 2025-09-03
- 1.4.0 — 2025-08-04
- … 10 more at https://npm.io/package/debug-logfmt/versions

## README

# debug-logfmt

<div align="center">
	<img width="800" src="https://i.imgur.com/R0cd2Gj.png" >
</div>

## Highlights

- Based on the popular [`debug`](https://www.npmjs.com/package/debug) module.
- Lazy level evaluation used logs levels.
- Level support: `info`, `warn` & `error` based from [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424).
- Message formatting Heroku [logfmt](https://brandur.org/logfmt) syntax.
- Colorized output via [`DEBUG_COLORS`](https://github.com/debug-js/debug#environment-variables) by default.
- [`debug.duration`](#measurement) for measurement.

## Install

```bash
$ npm install debug debug-logfmt --save
```

## Usage

### Multiple levels

Given a code like this one:

```js
const debug = require('debug-logfmt')('metascraper')

debug('retry', { url: 'https://kikobeats.com' })
debug.info('done', { time: Date.now() })
debug.warn('token expired', { timestamp: Date.now() })
debug.error('whoops', { message: 'expected `number`, got `NaN`' })
```

You can:
- Allow all the levels: `DEBUG=debug-logfmt*`
- Discard specific levels: `DEBUG="*,-metascraper:info*" node example.js`

### Measurement

Sometimes you need to log the duration of a function:

```js
const { setTimeout } = require('timers/promises')

const debug = require('debug-logfmt')('metascraper')

const duration = debug.duration()

setTimeout(1001).then(() => duration.error('timeout!'))
setTimeout(1100).then(() => duration.info('success'))
```

## API

### debug(env, [options])

#### env

*Required*<br>
Type: `string`

The env variable name to use for enabling logging using `DEBUG`.

#### options

##### levels

Type: `array`<br>
Default: `['debug', 'info', 'warn', 'error']`

The log levels available.

### debug.duration([...args])

It returns a function will print the duration in the next call.

```js
const duration = debug.duration('query')
const result = await db.query(query)
duration(result)
```

## License

**debug-logfmt** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/debug-logfmt/blob/master/LICENSE.md) License.<br>
Authored and maintained by Kiko Beats with help from [contributors](https://github.com/Kikobeats/debug-logfmt/contributors).

> [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · X [@Kikobeats](https://x.com/Kikobeats)

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