npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@perkos/util-logger

v1.0.1

Published

Structured logging utility for x402 protocol services

Readme

@perkos/util-logger

Structured logging utility for x402 protocol services. Provides environment-aware logging with JSON output for production and readable output for development.

Installation

npm install @perkos/util-logger

Usage

import { logger, createLogger, Logger } from '@perkos/util-logger';
import type { LogLevel, LogEntry, LoggerOptions } from '@perkos/util-logger';

// Use default logger instance
logger.info('Payment verified', { amount: '1000000', network: 'base' });
logger.warn('Retrying transaction', { attempt: 2 });
logger.error('Settlement failed', { error: 'Insufficient funds' });
logger.debug('Debug info', { payload: { ... } });

// Create custom logger
const customLogger = createLogger({
  isDev: true,           // Force development mode (readable output)
  minLevel: 'debug',     // Log all levels including debug
});

// Create child logger with context
const paymentLogger = logger.child({ service: 'payment', network: 'base' });
paymentLogger.info('Processing payment');
// => { timestamp: "...", level: "info", message: "Processing payment", service: "payment", network: "base" }

Output Formats

Production (JSON)

{"timestamp":"2024-01-15T10:30:00.000Z","level":"info","message":"Payment verified","amount":"1000000","network":"base"}

Development (Readable)

[2024-01-15T10:30:00.000Z] [INFO] Payment verified {"amount":"1000000","network":"base"}

API Reference

Logger Class

class Logger {
  constructor(options?: LoggerOptions);

  info(message: string, meta?: Record<string, unknown>): void;
  warn(message: string, meta?: Record<string, unknown>): void;
  error(message: string, meta?: Record<string, unknown>): void;
  debug(message: string, meta?: Record<string, unknown>): void;

  child(context: Record<string, unknown>): Logger;
}

Functions

| Function | Description | |----------|-------------| | logger | Default logger instance | | createLogger(options) | Create a new logger with custom options |

Types

type LogLevel = "info" | "warn" | "error" | "debug";

interface LogEntry {
  timestamp: string;
  level: LogLevel;
  message: string;
  [key: string]: unknown;
}

interface LoggerOptions {
  /** Force development mode output (readable format) */
  isDev?: boolean;
  /** Minimum log level to output */
  minLevel?: LogLevel;
  /** Custom log handler */
  handler?: (entry: LogEntry) => void;
}

Log Levels

| Level | Priority | Description | |-------|----------|-------------| | debug | 0 | Detailed debugging information | | info | 1 | General informational messages | | warn | 2 | Warning conditions | | error | 3 | Error conditions |

Set minLevel to filter out lower priority logs:

const logger = createLogger({ minLevel: 'warn' });
logger.debug('Not logged');  // Filtered out
logger.info('Not logged');   // Filtered out
logger.warn('Logged');       // ✓ Output
logger.error('Logged');      // ✓ Output

Custom Handler

Provide a custom handler to integrate with external logging services:

const logger = createLogger({
  handler: (entry) => {
    // Send to external service
    myLoggingService.log(entry);
  }
});

Environment Detection

The logger automatically detects the environment:

  • Development: NODE_ENV === "development" → readable format
  • Production: JSON format for log aggregation services

Override with isDev option:

const logger = createLogger({ isDev: true });  // Force readable format

Related Packages

License

MIT