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

hierarchical-area-logger

v0.2.9

Published

Hierarchical Area Logger

Readme

🌲 Hierarchical Area Logger

A lightweight, structured logging utility for TypeScript applications. It allows you to scope logs to specific Areas, track request flows via Event IDs, and dump the entire execution history for debugging or monitoring.

🚀 Features

  • Scoped Logging: Group logs by logical "areas" (e.g., db-layer, auth-service).
  • Traceability: Automatic Event ID generation and Parent Event ID mapping for distributed tracing.
  • Structured Payloads: Log rich objects and Error instances without losing metadata.
  • Snapshot Dumping: Retrieve the entire log state at any time for analysis or reporting.
  • Lightweight: Designed to be dependency-lite and predictable.

🛠 Installation

npm install hierarchical-area-logger
# or
yarn add hierarchical-area-logger

💡 Functionality Showcase

1. Basic Scoped Logging

Instead of a flat stream of text, the logger categorizes logs into logical areas.

import { createLogger } from 'hierarchical-area-logger';

const logger = createLogger({
  details: { service: 'payment-gateway' },
});

const checkout = logger.getArea('checkout-process');

checkout.info('User started checkout');
checkout.warn('Retry attempt 1 for payment');
checkout.error('Transaction failed', new Error('Timeout'));

// View the structured output
console.log(logger.dump());

2. Request Traceability

Track a request across your system by linking eventId and parentEventId.

const logger = createLogger({
    details: { service: 'payment-gateway' }
    path: '/api/v1/user',
    parentEventId: 'incoming-request-id-001'
});

console.log(logger.eventId); // Automatically generated unique ID
console.log(logger.parentEventId); // 'incoming-request-id-001'

3. Log Merging & State Management

You can append existing log data to a logger instance, which is useful for consolidating logs from multiple micro-tasks.

const mainLogger = createLogger({ details: { service: 'orchestrator' } });

const externalLogs = {
  'worker-1': [
    { type: 'info', message: 'Task complete', timestamp: Date.now() },
  ],
};

mainLogger.appendLogData(externalLogs);

📖 API Reference

createLogger(options)

Factory function to initialize a new Logger instance.

| Option | Type | Description | | --------------- | --------- | ------------------------------------------ | | details | Details | Metadata about the service or environment. | | path | string | (Optional) The execution path/route. | | parentEventId | string | (Optional) ID of the triggering event. |

LoggerInstance Methods

  • getArea(name: string): Returns a scoped logger for a specific logic block.

  • .info(msg, payload?)

  • .warn(msg, payload?)

  • .error(msg, error?)

  • dump(): Returns an object containing all logs indexed by their area names.

  • appendLogData(data): Manually injects log entries into the current instance.


🧪 Development & Testing

This project uses Vitest for unit testing.

# Run tests
npm test

# Run tests with coverage
npm run coverage

Note: The logger automatically creates a root area log entry labeled "Request received" if a path is provided during initialization.