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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@filipgorny/logger

v0.0.2

Published

Shared logging package with strategy pattern

Readme

@filipgorny/logger

Lightweight, colorful logging package with strategy pattern for flexible log output.

Features

  • Strategy pattern - Easily switch between logging strategies
  • Type-safe - Full TypeScript support
  • Multiple log levels - DEBUG, INFO, WARN, ERROR
  • Contextual logging - Add metadata to logs
  • Child loggers - Create loggers with inherited context
  • Colorized console output - Beautiful, readable logs with custom colors
  • Test-friendly - Automatically suppresses error logs in test environments
  • Clean format - Simple [HH:MM:SS] message format
  • Future-ready - Prepared for Datadog integration

Installation

npm install @filipgorny/logger
# or
pnpm add @filipgorny/logger

Usage

Basic Usage

import { createLogger, LogLevel } from "@filipgorny/logger";

const logger = createLogger("my-service", LogLevel.INFO);

logger.debug("Debugging info"); // Cyan
logger.info("Server started"); // Yellow
logger.warn("High memory usage"); // Magenta/Pink
logger.error("Connection failed"); // Red

Output Format

Logs are displayed in a clean, colorized format:

[08:46:40] Server started         # Yellow text, white timestamp
[08:46:45] High memory usage      # Pink text, white timestamp
[08:46:50] Connection failed      # Red text, white timestamp

Color Scheme

  • Timestamp [HH:MM:SS] - White
  • DEBUG - Cyan
  • INFO - Yellow
  • WARN - Magenta (Pink)
  • ERROR - Red

Custom Strategy

import { Logger, LogLevel, LogStrategy } from "@filipgorny/logger";

class CustomStrategy implements LogStrategy {
  log(entry: LogEntry): void {
    // Your custom logging logic
  }
}

const logger = new Logger(new CustomStrategy(), {
  service: "my-service",
  level: LogLevel.INFO,
});

Child Loggers

const logger = createLogger("api-service");
const requestLogger = logger.child({ requestId: "123", userId: "abc" });

requestLogger.info("Processing request"); // Includes requestId and userId

Switching Strategies at Runtime

import { ConsoleLogStrategy } from "@filipgorny/logger";

// Start with console
logger.setStrategy(new ConsoleLogStrategy());

// Switch to custom strategy
logger.setStrategy(new CustomStrategy());

Test Environment

The logger automatically detects test environments (NODE_ENV=test or Jest) and suppresses ERROR level console output to keep test output clean.

API

createLogger(serviceName, level?)

Create a new logger instance.

  • serviceName: Name of the service (e.g., 'llm-service')
  • level: Minimum log level (default: LogLevel.INFO)

Logger Methods

  • debug(message, context?) - Debug level logging
  • info(message, context?) - Info level logging
  • warn(message, context?) - Warning level logging
  • error(message, error?, context?) - Error level logging
  • child(context) - Create a child logger with inherited context
  • setStrategy(strategy) - Change the logging strategy
  • setLevel(level) - Change the minimum log level

Log Levels

  • DEBUG - Detailed debugging information
  • INFO - General informational messages (default)
  • WARN - Warning messages
  • ERROR - Error messages

Strategies

ConsoleLogStrategy (Default)

Logs to console with colorized output and clean timestamp format.

Custom Strategy

Implement the LogStrategy interface:

import { LogStrategy, LogEntry } from "@filipgorny/logger";

class MyCustomStrategy implements LogStrategy {
  log(entry: LogEntry): void {
    // Your custom logging logic
    console.log(`[${entry.service}] ${entry.message}`);
  }
}

Advanced Features

Table Logging

Display data in a beautiful table format:

logger.table(
  [
    { name: "John", age: 30, city: "NYC" },
    { name: "Jane", age: 25, city: "LA" },
  ],
  [
    { key: "name", header: "Name" },
    { key: "age", header: "Age" },
    { key: "city", header: "City" },
  ],
);

License

MIT