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

@schafevormfenster/logging

v0.1.3

Published

Foundational layer for observability and diagnostics - structured logging, error normalization, and content truncation

Downloads

246

Readme

Logging

Core logging utilities for structured logging with Pino.

Purpose

Minimal, focused logging package providing:

  • Structured logging via Pino
  • Error normalization for consistent logging
  • Content truncation utilities

Installation

pnpm add @schafevormfenster/logging

API

getLogger(name: string): AppLogger

Creates a Pino logger instance with the given name.

import { getLogger } from "@schafevormfenster/logging";

const logger = getLogger("my-service");

logger.info({ userId: "123" }, "User logged in");
logger.error({ error: new Error("Failed") }, "Operation failed");
logger.security({ action: "login", userId: "123" }, "Login attempt");

Configuration:

  • PINO_LOG_LEVEL - Log level (default: "info")
    • Options: "trace", "debug", "info", "warn", "error", "fatal"

normalizeError(error: unknown): NormalizedError

Normalizes any error value into a consistent structure for logging.

import { normalizeError } from "@schafevormfenster/logging";

try {
  await riskyOperation();
} catch (error) {
  const normalized = normalizeError(error);
  logger.error(normalized, "Operation failed");
}

Features:

  • Handles Error instances, error-like objects, strings, and primitives
  • Preserves error properties (name, code, statusCode, stack)
  • Traverses error cause chains (ES2022 Error.cause)
  • Prevents infinite recursion in circular cause chains
  • Type-safe with NormalizedError interface

truncateContent(content: string, options?: TruncateOptions): string

Truncates strings to a maximum length with customizable behavior.

import { truncateContent } from "@schafevormfenster/logging";

// Basic truncation
const short = truncateContent("Very long message...", { maxLength: 20 });
// => "Very long message..."

// Truncate in middle
const middle = truncateContent("path/to/very/long/file.txt", {
  maxLength: 20,
  position: "middle"
});
// => "path/to...file.txt"

// Custom ellipsis
const custom = truncateContent("Long text", {
  maxLength: 10,
  ellipsis: " [more]"
});
// => "Long [more]"

Options:

  • maxLength - Maximum length (default: 100)
  • ellipsis - Truncation indicator (default: "...")
  • breakOnWord - Break at word boundaries (default: true)
  • position - Where to truncate: "end", "middle", "start" (default: "end")

Examples

Complete logging workflow

import { getLogger, normalizeError, truncateContent } from "@schafevormfenster/logging";

const logger = getLogger("api.users");

async function createUser(userData: unknown) {
  try {
    // Log incoming data (truncated for security)
    const preview = truncateContent(JSON.stringify(userData), { maxLength: 100 });
    logger.debug({ data: preview }, "Creating user");

    const user = await db.users.create(userData);
    logger.info({ userId: user.id }, "User created successfully");
    
    return user;
  } catch (error) {
    // Normalize error for consistent logging
    const normalized = normalizeError(error);
    logger.error(normalized, "Failed to create user");
    throw error;
  }
}

Migration from Previous Versions

Removed:

  • measureTime() - Use timing utilities directly in your app
  • logPerformance() - Use timing utilities directly in your app
  • logLevelConfig - Use PINO_LOG_LEVEL environment variable
  • All redaction utilities - Moved to @schafevormfenster/security

Changed:

  • Package now exports from logger.ts instead of index.ts
  • Imports remain the same: import { ... } from "@schafevormfenster/logging"