New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

logger-base

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logger-base

debug module using logfmt format

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
139
124.19%
Maintainers
1
Weekly downloads
 
Created
Source

logger-base

Security Status Vulnerabilities npm version License: MIT

Highlights

Security

logger-base maintains the highest security standards:

  • Zero known vulnerabilities (npm audit clean)
  • Automated security validation (pre-publish security checks)
  • Secure dependency management (version overrides for vulnerable packages)
  • Comprehensive security documentation (SECURITY.md)

Run security validation: npm run security:validate

Install

$ npm install logger-base --save

Usage

Multiple levels

Given a code like this one:

const debug = require('logger-base')('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=logger-base*
  • 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('logger-base')('metascraper')

const duration = debug.duration()

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

Custom Options

You can customize the logger behavior with options:

const debug = require('logger-base')('myapp', {
  // Custom log levels
  levels: ['info', 'warn', 'error', 'fatal'],
  
  // Disable colors
  colors: false,
  
  // Custom duration format
  durationFormat: (ms) => `${Math.round(ms)}ms`,
  
  // Custom prefix
  prefix: (namespace) => `[${namespace}] `,
  
  // Custom encoding (e.g., for structured logging)
  encode: (obj) => JSON.stringify(obj)
})

Using Custom Encoding

const debug = require('logger-base')('myapp', {
  encode: (obj) => {
    // Convert object to your preferred format
    return Object.entries(obj)
      .map(([key, value]) => `${key}="${String(value)}"`)
      .join(' ')
  }
})

debug('user action', { userId: 123, action: 'login' })
// Output: user action userId="123" action="login"

Custom Duration Format

const debug = require('logger-base')('myapp', {
  durationFormat: (ms) => {
    if (ms < 1000) return `${ms}ms`
    if (ms < 60000) return `${(ms / 1000).toFixed(2)}s`
    return `${(ms / 60000).toFixed(2)}m`
  }
})

const duration = debug.duration('operation')
// After 1500ms: duration=1.50s

API

debug(env, [options])

env

Required
Type: string

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

options

Type: object
Default: {}

Configuration options for the debug logger.

levels

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

The log levels available. Each level will be accessible as a method on the debug instance (e.g., debug.info(), debug.warn(), debug.error()).

encode

Type: function
Default: The default logfmt encoder

Custom encoding function for converting objects to logfmt format. The function receives an object and should return a logfmt-formatted string.

const debug = require('logger-base')('myapp', {
  encode: (obj) => {
    // Custom encoding logic
    return Object.keys(obj).map(key => `${key}=${obj[key]}`).join(' ')
  }
})
colors

Type: boolean
Default: true (unless DEBUG_COLORS=false in environment)

Enable or disable colored output. When disabled, log messages will not include ANSI color codes.

const debug = require('logger-base')('myapp', {
  colors: false
})
durationFormat

Type: function
Default: pretty-ms formatter

Custom format function for duration formatting. The function receives a number (milliseconds) and should return a formatted string.

const debug = require('logger-base')('myapp', {
  durationFormat: (ms) => {
    return `${ms}ms`
  }
})
prefix

Type: function
Default: The default prefix formatter

Custom prefix function for formatting log messages. The function receives the namespace (string) and color code (number), and should return a formatted prefix string.

const debug = require('logger-base')('myapp', {
  prefix: (namespace, color) => {
    return `[${namespace}] `
  }
})

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)

Security

logger-base is committed to maintaining the highest security standards. We implement comprehensive security measures including:

Security Features

  • Zero vulnerabilities: Regular automated security audits ensure clean dependency tree
  • Automated validation: Pre-publish security checks prevent vulnerable releases
  • Secure coding practices: Source code scanning for security anti-patterns
  • Dependency management: Version overrides for vulnerable transitive dependencies

Security Commands

# Run comprehensive security validation
npm run security:validate

# Audit all dependencies
npm run security:audit

# Run all security checks (audit + validation)
npm run security:check

Reporting Security Issues

Please review our Security Policy for information on reporting vulnerabilities and our response procedures.

License

logger-base © 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 29 Jan 2026

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