You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

debug-logfmt

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debug-logfmt

debug module using logfmt format

1.4.0
latest
Source
npmnpm
Version published
Weekly downloads
29K
-14.45%
Maintainers
0
Weekly downloads
 
Created
Source

debug-logfmt

Highlights

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

Keywords

debug

FAQs

Package last updated on 04 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts