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

leylines

v0.3.4

Published

Local scoped structured logs for applications and coding agents

Readme

Leylines

Leylines is a local scoped log store for applications and coding agents. It captures structured entries with stable scopes, queryable properties, redaction before persistence, bounded retention, and deterministic CLI/JSON output.

It ships as one package with:

  • a Node.js API for writing, querying, tailing, and expanding logs
  • a ley CLI for agent and operator workflows
  • a Vite development plugin plus browser and Tauri loggers

Leylines uses the built-in node:sqlite module, so it targets modern Node.js runtimes that include that API.

pnpm add leylines

Node API

import { openScopedLogs } from 'leylines'

const logs = openScopedLogs()
const logger = logs.logger({
  scope: 'checkout.cart',
  properties: { request: { id: 'req-123' } },
})

logger.info('cart opened', { properties: { cartId: 'cart-1' } })
logger.error('checkout failed', {
  properties: { cartId: 'cart-1' },
  error: new Error('payment declined'),
})

const page = logs.query({
  scopePrefix: 'checkout',
  minLevel: 'warn',
  properties: [{ path: 'cartId', equals: 'cart-1' }],
})

console.log(page.entries)
logs.close()

The Node API is disabled when NODE_ENV is production: it does not create a database, writes return undefined, and queries return no entries. Pass production: true to openScopedLogs only when production capture is intentional.

Each entry has a stable id, timestamp, sequence, level, scope, message, metadata, structured properties, and optional error details. Supported levels are debug, info, warn, and error.

debug entries are hidden from default human-style queries unless includeDebug is set or levels: ['debug'] is requested explicitly.

CLI

The CLI reads the same inferred store as the Node API.

ley
ley --scope-prefix checkout --min-level warn
ley --property request.id=req-123
ley scopes
ley expand '<entry-id>:properties.payload'
ley path

Filtering supports:

  • time: --since, --until
  • entry boundaries: --before, --after
  • levels: --level debug,info, --min-level warn, --include-debug
  • scopes: --scope, --scope-prefix
  • text: --text, --regex
  • properties: --property path=value
  • pagination: --limit

Default output is compact and chronological, which works well for quick human or agent triage. Use --json when output will be parsed, stored, compared, or when exact entry fields such as ids, sequences, and metadata are needed.

Vite

// vite.config.ts
import { defineConfig } from 'vite'
import { leylines } from 'leylines/vite'

export default defineConfig({
  plugins: [
    leylines({
      scope: 'browser',
      captureConsole: ['warn', 'error'],
      captureErrors: true,
      captureRejections: true,
      stripProduction: true,
    }),
  ],
})

The plugin registers a local ingestion endpoint and injects the browser logger during Vite serve mode. Production build capture is quiet by default. With stripProduction: true, production builds also remove standalone browser logger calls such as logger.info('router', 'route loaded').

Vite dev-server warnings and errors can also be captured directly from Vite's logger without changing normal terminal output:

leylines({
  viteLogger: {
    scope: 'dev.vite',
    levels: ['warn', 'error'],
  },
})
ley --scope-prefix dev.vite --min-level warn --json

Tauri apps can forward @tauri-apps/plugin-log records through the browser logger connected by the Vite plugin:

pnpm add @tauri-apps/plugin-log
import { attachTauriLogger } from 'leylines/tauri'

const detachTauriLogs = attachTauriLogger()

Forwarded Tauri records use the tauri scope by default. Tauri trace records map to Leylines debug entries.

PostHog product metrics can be redirected into the same local store during development:

leylines({
  posthog: true,
})

posthog.init(projectKey, {
  api_host: '/__leylines/posthog',
})

Application code can also use the browser logger directly:

import { logger } from 'leylines/browser'

logger.connect({
  endpoint: '/__scoped_logs',
  scope: 'browser',
})

logger.info('router', 'route loaded', { route: '/settings' })

Redaction And Retention

Redaction runs before entries are persisted. Leylines redacts common secret-looking property names such as token, authorization, password, secret, cookie, and apiKey, plus credential-shaped values such as bearer tokens.

const logs = openScopedLogs({
  redaction: {
    rules: [{ name: /^stripe/i, replacement: '[STRIPE SECRET]' }],
  },
  retention: {
    maxEntries: 10_000,
    maxAgeMs: 7 * 24 * 60 * 60 * 1000,
  },
})

Retention runs during store maintenance: when a store opens, when it closes, and periodically during writes.

Large values are collapsed in default entries and can be retrieved later with logs.expand(id) or ley expand.

Agent Workflow

Start broad, discover scopes, then pivot through structured properties:

ley --limit 30
ley scopes
ley --scope-prefix checkout
ley --property request.id=req-123 --json

Agents can start with compact output when reading logs as context. Switch to JSON for automation or exact fields instead of inspecting SQLite files directly. Store schema and file layout are internal implementation details.

Documentation

  • Getting Started gets a store, Node logger, CLI, and Vite browser capture working.
  • Concepts explains entries, scopes, metadata, properties, redaction, retention, and collapsed values.
  • Node API covers direct store usage, child loggers, queries, tailing, and expansion.
  • Vite And Browser covers browser capture and singleton logger usage.
  • CLI And Agent Workflows covers investigation patterns and JSON output for agents.
  • PostHog Development Capture covers redirecting local PostHog events into Leylines.