Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

debug-logfmt

Kikobeats149.3kMIT1.4.0TypeScript support: included

debug module using logfmt format

debug, debugger, herokubunyan, log, logfmt, logger, logging, winston

readme

debug-logfmt

Highlights

  • Based on the popular debug module.
  • Lazy level evaluation used logs levels.
  • Level support: info, warn & error based from RFC 5424.
  • Message formatting Heroku logfmt syntax.
  • Colorized output via DEBUG_COLORS by default.
  • debug.duration for measurement.

Install

$ npm install debug-logfmt --save

Usage

Multiple levels

Given a code like this one:

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:

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
Type: string

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

options

levels

Type: array
Default: ['debug', 'info', 'warn', 'error']

The log levels available.

debug.duration([...args])

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

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

License

debug-logfmt © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · X @Kikobeats

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.4.0 (2025-08-01)

Features

1.3.0 (2025-08-01)

Features

1.2.6 (2025-07-03)

1.2.5 (2025-01-12)

1.2.4 (2025-01-10)

1.2.3 (2024-09-13)

Bug Fixes

1.2.2 (2024-01-16)

1.2.1 (2024-01-16)

1.2.0 (2023-10-08)

Features

1.1.0 (2023-10-07)

Features

  • don't print diff information (d874c16)

1.0.4 (2019-10-07)

1.0.3 (2019-08-23)

1.0.2 (2019-06-03)

Bug Fixes

  • package: update logfmt to version 1.3.2 (90640f6)

1.0.1 (2019-05-21)

1.0.0 (2019-05-21)

0.0.1 (2019-05-21)

Bug Fixes

Build System

  • no-release: first commit (fdea7ad)