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

websockets-logger

v0.3.1

Published

Lightweight WebSocket logger that forwards console output to a centralized hub.

Readme

websockets-logger

A tiny TypeScript-first helper that forwards your application logs to a Cloudflare Durable Object hub and lets you inspect everything through the console-omattic-com UI. Drop it into any browser or Node.js project, keep your existing console.* calls, and get a centralized stream of JSON-friendly log events.

Quick start

Install the package inside your app (once this workspace is published you can reference it via a local path or private registry):

pnpm add websockets-logger

Initialize the logger as early as possible in your app:

import { initializeWebSocketLogger, wsLog } from 'websockets-logger';

initializeWebSocketLogger({
  wsUrl: 'wss://websockets.omattic.com/hub',
  source: 'my-app', // optional – defaults to host/pid + random suffix
  apiKey: 'your-api-key', // optional – for authenticated hubs
});

wsLog.info('Hello central console');

If you prefer to keep using console.*, flip on the auto-patching helper:

initializeWebSocketLogger({
  wsUrl: 'wss://websockets.omattic.com/hub',
  source: 'marketing-site',
  apiKey: 'your-api-key', // optional – for authenticated hubs
  patchConsole: true,
});

With patchConsole: true the module swaps the global console methods so every call goes through the logger and optionally prints locally. By default local printing is disabled to avoid double output; enable it by passing consolePassthrough: true or enableConsole: true.

Options

| Option | Default | Notes | | --- | --- | --- | | wsUrl | – | Required WebSocket endpoint, e.g. wss://websockets.omattic.com/hub from websockets-omattic-com. | | source | hostname / pid + random | Acts as the clientId inside the Durable Object. Show up in the console UI as the emitter. | | topic | logs | Broadcast topic used when sending messages. Leave as-is to interoperate with the console worker and UI. | | subscriptionTopic | source | Initial subscription topic sent on connection. Normally you should not change this. | | enableConsole | true (or false when patchConsole is set) | Mirror messages to the original console methods that were present during initialization. | | bufferMessages | true | Queue log entry objects while the socket reconnects. | | maxBufferSize | 100 | Upper bound for the in-memory buffer. Oldest messages are dropped first. | | reconnectInterval | 5000 ms | Automatic reconnect cadence. Set to 0 to disable. | | onConnectionChange | – | (state) => void callback with connecting, connected, or disconnected. Useful for status indicators. | | onMessage | – | Receive raw messages coming from the hub (handy if you extend the DO to push commands). | | webSocketFactory | globalThis.WebSocket | Supply your own implementation when running outside the browser, e.g. () => new (require('ws'))(url). | | initialContext | {} | Key/value payload merged into every log message. Update at runtime via logger.updateContext(). | | apiKey | – | Optional API key for authentication. Automatically included in the subscription message payload. Works in both browser and Node.js environments. | | patchConsole | false | Only on initializeWebSocketLogger. Auto routes console calls through the logger. | | consoleLevels | all | Restrict which console methods are patched. | | consolePassthrough | mirrors enableConsole | When patching console, forward the call to the original console after logging. |

Runtime helpers

import {
  WebSocketLogger,
  initializeWebSocketLogger,
  getWebSocketLogger,
  patchConsole,
  unpatchConsole,
  wsLog,
} from 'websockets-logger';
  • WebSocketLogger – instantiate manually if you need multiple isolated loggers.
  • initializeWebSocketLogger – creates a singleton, optionally patches the global console, and returns the instance.
  • getWebSocketLogger – retrieve the singleton or null.
  • patchConsole / unpatchConsole – control console interception explicitly.
  • wsLog – drop-in replacement object with log/error/warn/info/debug plus setRequestId, setContext, updateContext, clearContext.

Request-scoped metadata

const logger = initializeWebSocketLogger({ wsUrl: HUB_URL });

logger.setRequestId('abc-123');
logger.updateContext({ userId: 'uid_42', featureFlag: 'beta-dashboard' });
logger.info('User opened dashboard');
logger.clearContext(['featureFlag']);
logger.clearRequestId();

Every payload delivered to the hub includes the timestamp, level, source, optional request id, and context blob. The console-omattic-com UI already highlights requestId and prettifies JSON content; adding more context lets you extend that view without changing the worker.

Using inside Node.js

Pass your own WebSocket implementation and patch the console:

import WebSocket from 'ws';
import { initializeWebSocketLogger } from 'websockets-logger';

initializeWebSocketLogger({
  wsUrl: 'wss://websockets.omattic.com/hub',
  source: `worker-${process.pid}`,
  apiKey: 'your-api-key', // optional – for authenticated hubs
  webSocketFactory: (url) => new WebSocket(url),
  patchConsole: true,
  enableConsole: true, // still prints locally
});

Relationship to the hub and console projects

  • websockets-omattic-com hosts the Cloudflare Worker + Durable Object hub that relays messages between clients. This logger automatically subscribes using its source as clientId and publishes log entries to the shared logs topic.
  • console-omattic-com is the React UI that subscribes to the all topic and renders incoming log events. If you follow the defaults, every log produced through this module appears there instantly with request id and JSON detection.

Development

pnpm install
pnpm build

The build pipeline uses tsup to emit dual ESM/CommonJS bundles plus declaration files into dist/. To start iterating locally you can pnpm link --global and consume the package in another repo via pnpm link --global websockets-logger.

Continuous publishing

  • GitHub Actions workflow: .github/workflows/publish.yml.
  • Trigger: every push to main after lint/build.
  • Publishes with pnpm publish --access public when the package.json version is not already on npm.
  • Requires an NPM_TOKEN repository secret with publish rights to the websockets-logger package.