Skip to main content

Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
•JSR Score100%•
License
Apache-2.0
•
Downloads398/wk
•
Publisheda day ago (0.0.10)

Structured logging for NetScript services, packages, workers, and jobs, built on LogTape: configure once at startup, create category-scoped loggers, and bind request-scoped context across the runtime.

@netscript/logger

JSR CI Docs

Structured logging for NetScript services, packages, workers, and jobs, built on LogTape: configure once at startup, create category-scoped loggers, and bind request-scoped context across the runtime.

Every NetScript process logs through the same hierarchy: configureLogging() sets up LogTape once — human-readable text in local development, structured JSON in production — and the creator functions hand out loggers under a consistent netscript·… category tree, so a service, a worker, and a job all emit records an operator can filter the same way. withContext() binds request-scoped fields onto every record emitted inside a callback, and the middleware and oRPC subpaths wire that context into HTTP and RPC handling automatically.

Why teams use it

  • Category-scoped creators — createServiceLogger, createPackageLogger, createWorkerLogger, createJobLogger, and createChildLogger produce loggers with a consistent NetScript category hierarchy.
  • One-shot configuration — configureLogging and ensureLogging set up LogTape with environment-aware sinks; isLoggingConfigured and resetLogging cover lifecycle and test isolation.
  • Hono request logging — @netscript/logger/middleware exposes loggerMiddleware, injecting a request-scoped logger and request ID and logging start, completion, and failure with sensitive-field redaction.
  • oRPC integration — @netscript/logger/orpc exposes LoggingPlugin and createLoggingPlugin to log oRPC handler and client interceptions, correlated per request by requestId even under concurrent traffic. Debug-mode input logs redact sensitive fields, extensible with redactFields.
  • LogTape contract re-exported — getLogger, getConsoleSink, withContext, and the Logger, LogRecord, LogLevel, and Sink types pass through unchanged, so anything LogTape can do stays available.

Install

deno add jsr:@netscript/logger@<version>

Pin <version> to match your installed CLI; bare jsr:@netscript/* specifiers do not resolve on the pre-release line.

Quick example

import { configureLogging, createServiceLogger, withContext } from '@netscript/logger';

await configureLogging({ level: 'info' });

const logger = createServiceLogger('users');
logger.info('Service starting', { port: 3000 });

// Bind request-scoped fields onto every record emitted in the callback.
withContext({ requestId: 'req-42' }, () => {
  logger.info('Handling request');
});

In development this prints readable lines under the service category (netscript·services·users Service starting); in production the same calls emit structured JSON. Use ensureLogging() instead of configureLogging() on shared startup paths that may run more than once.

oRPC request correlation

LoggingPlugin reuses an incoming requestId from oRPC context (such as the ID propagated by loggerMiddleware / X-Request-ID in @netscript/service) and falls back to a fresh per-request ID when absent, keeping HTTP access logs, RPC logs, and procedure handlers correlated:

import { LoggingPlugin } from '@netscript/logger/orpc';

const plugin = new LoggingPlugin({
  serviceName: 'orders',
  redactFields: ['brief'],
});
void plugin;

Public surface

Entry What it gives you
. configureLogging / ensureLogging, category-scoped creators, LogTape re-exports
./middleware loggerMiddleware and request-ID/logger injection helpers for Hono
./orpc LoggingPlugin / createLoggingPlugin for oRPC handler and client logging

The always-current symbol list is deno doc jsr:@netscript/logger@<version> (pin <version> on the pre-release line, as above).

Docs

Compatibility

Runs wherever LogTape does — Deno, Node.js, and Bun. Environment-aware sink selection reads environment variables, so grant --allow-env under Deno. The middleware subpath targets Hono 4 and the oRPC subpath targets @orpc/server 1.x; both stay out of your module graph unless imported.

License

Apache-2.0 — see LICENSE. Published to JSR with cryptographically verified provenance.

Examples

Example 1

import { configureLogging, createServiceLogger } from '@netscript/logger';

await configureLogging({ level: 'info' });

const logger = createServiceLogger('users');
logger.info('Service starting', { port: 3000 });

Example 2

import { loggerMiddleware } from '@netscript/logger/middleware';
import { LoggingPlugin } from '@netscript/logger/orpc';
Built and signed on
GitHub Actions

Add Package

deno add jsr:@netscript/logger

Import symbol

import * as logger from "@netscript/logger";
or

Import directly with a jsr specifier

import * as logger from "jsr:@netscript/logger@^0.0.10";