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

@resq-sw/logger

v0.1.1

Published

Structured logging with log levels for Node.js and Bun

Readme

@resq-sw/logger

Structured logging with log levels, decorators, and singleton management for Node.js and Bun.

Installation

bun add @resq-sw/logger

Zero runtime dependencies.

Quick Start

import { Logger, LogLevel } from "@resq-sw/logger";

const log = Logger.getLogger("[MyService]");

log.info("Server started", { port: 3000 });
log.warn("Disk usage high", { percent: 92 });
log.error("Connection failed", new Error("timeout"), { host: "db" });
log.debug("Cache hit", { key: "user:123" });

Output format: YYYY-MM-DD HH:mm:ss.SSS LEVEL [context] message {data}

API Reference

Logger Class

Logger.getLogger(context, options?): Logger

Returns a singleton Logger instance for the given context. Subsequent calls with the same context return the same instance.

new Logger(context, options?)

Creates a new Logger instance.

| Option | Type | Default | Description | |--------|------|---------|-------------| | minLevel | LogLevel | env-based | Minimum log level | | includeTimestamp | boolean | -- | Include timestamps | | colorize | boolean | -- | Colorize output | | logToFile | boolean | -- | Write to file (server-side) | | filePath | string | -- | Log file path |

Level resolution priority: options.minLevel > LOG_LEVEL env > BUN_LOG_LEVEL env > LogLevel.ERROR (production) / LogLevel.ALL (development).

Logger.setGlobalLogLevel(level: LogLevel): void

Sets the minimum log level for all existing logger instances.

Log Levels

enum LogLevel {
  NONE  = 0,  // No logging
  ERROR = 1,  // Errors only
  WARN  = 2,  // Errors + warnings
  INFO  = 3,  // + informational
  DEBUG = 4,  // + debug messages
  TRACE = 5,  // + trace messages
  ALL   = 6,  // Everything
}

Logging Methods

All methods accept an optional data parameter (Record<string, unknown>).

| Method | Min Level | Console Method | Description | |--------|-----------|----------------|-------------| | info(message, data?) | INFO | console.info | Informational messages | | error(message, error?, data?) | ERROR | console.error | Errors (auto-serializes Error objects) | | warn(message, data?) | WARN | console.warn | Warnings | | debug(message, data?) | DEBUG | console.debug | Debug messages | | trace(message, data?) | TRACE | console.debug | Trace messages (most verbose) | | action(message, data?) | INFO | console.info | Server actions / user interactions | | success(message, data?) | INFO | console.info | Success confirmations |

Grouping

log.group("Request Processing");
log.info("Step 1");
log.info("Step 2");
log.groupEnd();

Timing

logger.time<T>(label, fn): Promise<T>

Measures and logs execution time of a sync or async function.

const result = await log.time("DB query", async () => {
  return await db.query("SELECT * FROM users");
});
// Logs: "DB query completed" { duration: "12.34ms" }

On error, logs the failure with duration and rethrows.

Decorators

@Log(options?)

Logs method entry and exit with optional argument and return value logging.

| Option | Type | Default | Description | |--------|------|---------|-------------| | logArgs | boolean | true | Log method arguments | | logResult | boolean | false | Log return value | | message | string | method name | Custom message prefix | | level | LogLevelString | "debug" | Log level to use |

class UserService {
  @Log({ logArgs: true, logResult: true, level: "info" })
  async getUser(id: string) { return { id, name: "John" }; }
}

@LogTiming(options?)

Logs method execution time. Works with both sync and async methods.

| Option | Type | Default | Description | |--------|------|---------|-------------| | label | string | ClassName.methodName | Custom timing label | | threshold | number | 0 | Only log if duration exceeds this (ms) | | level | LogLevelString | "info" | Log level to use |

class DataService {
  @LogTiming({ threshold: 100 })
  async fetchData() { /* only logged if > 100ms */ }
}

@LogError(options?)

Wraps method in try/catch, logs errors with stack traces.

| Option | Type | Default | Description | |--------|------|---------|-------------| | rethrow | boolean | true | Rethrow after logging | | message | string | "<method> error" | Custom error prefix | | includeStack | boolean | true | Include stack trace in log |

class Api {
  @LogError({ rethrow: false, message: "API call failed" })
  async callApi() { throw new Error("Network error"); }
  // Error is logged but swallowed; method returns undefined
}

@LogClass(options?)

Class decorator that applies logging to all methods on the prototype.

| Option | Type | Default | Description | |--------|------|---------|-------------| | exclude | string[] | [] | Method names to skip | | logCalls | boolean | true | Log method entry/exit | | timing | boolean | false | Log execution times |

@LogClass({ exclude: ["internalHelper"], timing: true })
class MyService {
  publicMethod() { /* logged with timing */ }
  internalHelper() { /* not logged */ }
}

Types

Exported types: LogData, LoggerOptions, LogLevel, LogLevelString, ColorKey, LogEntry, LogTransport, LogMethodOptions, LogTimingOptions, LogErrorOptions, LogClassOptions.

License

Apache-2.0