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

logsetu-js

v0.1.0

Published

Lightweight LogSetu SDK for Next.js, React and Node.js — ship logs to your self-hosted LogSetu server

Readme

logsetu-js

Tiny (≈2.5 KB gzipped), zero-dependency SDK that ships logs from Next.js, React and Node.js to your self-hosted LogSetu server. Batches, retries with backoff, never blocks your app, and works in both the browser and on the server.

npm install logsetu-js

Quick start

import { LogSetu } from "logsetu-js";

const logger = LogSetu.init({
  apiKey: process.env.NEXT_PUBLIC_LOGSETU_API_KEY!, // from the LogSetu dashboard → Projects
  endpoint: "https://logs.example.com",             // your LogSetu server
  environment: "production",
  source: "nextjs-web",
});

logger.info("User logged in", { userId: 123 });
logger.warn("Cart abandoned", { cartId: "c_9" });
logger.error("Payment failed", { error: err, orderId: 456 }); // Error objects are serialized with stack
logger.captureException(err, { where: "checkout" });          // any thrown value → error log + stack

LogSetu.init also registers a default client, so anywhere else you can simply call LogSetu.info(...), LogSetu.captureException(...) etc. without passing the logger around.

Next.js (App Router)

1. Server side — instrumentation.ts

Captures unhandled errors from Server Components, Route Handlers, Server Actions and middleware, plus unhandled rejections / uncaught exceptions in the Node process.

// instrumentation.ts (project root or src/)
import { registerLogSetu, createOnRequestError } from "logsetu-js/next";

export function register() {
  registerLogSetu({
    apiKey: process.env.LOGSETU_API_KEY!,
    endpoint: process.env.LOGSETU_ENDPOINT!,
    environment: process.env.NODE_ENV,
    source: "nextjs-server",
  });
}

export const onRequestError = createOnRequestError();

Then log from any server code with the default client:

import { LogSetu } from "logsetu-js";

export default async function Page() {
  LogSetu.info("Rendering dashboard", { path: "/dashboard" });
  ...
}

Optionally wrap Route Handlers to get per-request logs with status and duration:

import { withLogSetu } from "logsetu-js/next";

export const GET = withLogSetu(async (req) => Response.json({ ok: true }), { logRequests: true });

2. Browser side — a client module

// lib/logsetu.ts
"use client";
import { LogSetu } from "logsetu-js";

export const logger = LogSetu.init({
  apiKey: process.env.NEXT_PUBLIC_LOGSETU_API_KEY!,
  endpoint: process.env.NEXT_PUBLIC_LOGSETU_ENDPOINT!,
  environment: process.env.NODE_ENV,
  source: "nextjs-web",
});

The same project API key works for both browser and server. Logs sent from the browser are flushed with navigator.sendBeacon when the tab is hidden or closed, so nothing is lost on navigation.

3. React error boundary

import { LogSetuErrorBoundary } from "logsetu-js/react";

<LogSetuErrorBoundary fallback={(error, reset) => <button onClick={reset}>Try again</button>}>
  <App />
</LogSetuErrorBoundary>

Uncaught render errors are reported with the React component stack and the current URL. Works in plain React (Vite / CRA) too — logsetu-js/react has no Next.js dependency.

Options

| Option | Default | Description | |---|---|---| | apiKey | — | Project API key | | endpoint | — | Base URL of your LogSetu server | | environment | NODE_ENV or "production" | Tag on every log | | source | "browser" / "node" | Tag on every log | | level | "debug" | Minimum level to send | | defaultMeta | {} | Metadata merged into every log (e.g. { tenant_id }) | | flushInterval | 2000 | ms between flushes | | batchSize | 10 | Flush as soon as this many logs are queued | | maxQueueSize | 1000 | Drop oldest beyond this | | maxRetries | 3 | Retries with exponential backoff on 429 / 5xx / network errors | | enabled | true | false turns the SDK into a no-op (tests, local dev) | | console | false | Also print logs to the console | | debug | false | Print every transport failure (otherwise only the first) | | beforeSend | — | (entry) => entry \| null to scrub or drop logs | | fetch | global fetch | Custom fetch implementation |

API

  • logger.debug / info / warn / error / fatal(message, meta?)
  • logger.log(level, message, meta?)
  • logger.captureException(error, meta?, level = "error")
  • logger.setContext(meta) — merge metadata into all subsequent logs (user id, tenant, release…)
  • logger.child(meta, { source? }) — a logger sharing the same queue with extra metadata
  • await logger.flush() — send everything queued now (e.g. before a serverless function returns)
  • await logger.close() — flush and stop timers

Everything is fully typed; .d.ts files ship with the package (ESM + CJS).

Serverless / edge

Route Handlers on Vercel and similar platforms may freeze before the 2s flush timer fires — call await LogSetu.flush() at the end of the handler. Errors are always flushed immediately by withLogSetu and createOnRequestError. The core client has no Node-only APIs and runs in the Edge runtime.

License

MIT