Zero-config function-level structured logging for JavaScript and TypeScript services.
Most app logs are either too noisy or not structured enough to debug production issues quickly. logpilot wraps your functions and emits consistent events (args, duration, result/error, context) without forcing a logger migration.
- Wraps sync/async functions with structured success/error events
- Adds timestamps, duration, and function metadata automatically
- Supports redaction of sensitive keys (
password,token, etc.) - Offers global config + scoped child loggers
- Includes Express/Fastify-compatible middleware helper
- Can wrap object/class methods for bulk instrumentation
npm install @darksol/logpilotimport { pilot } from "@darksol/logpilot";
pilot.configure({
level: "info",
format: "auto",
context: { service: "billing-api" }
});
const sum = pilot((a: number, b: number) => a + b);
const result = await sum(2, 3);import { pilot } from "@darksol/logpilot";
const getUser = pilot(async (id: string) => ({ id, role: "admin" }));
await getUser("u_1");
const reqLog = pilot.child({ requestId: "req-42" });
reqLog.info("request started", { route: "/users/:id" });// Wrap methods on an existing object
class Service {
getOrder(id: string) {
return { id, status: "ok" };
}
}
const service = pilot.wrap(new Service());
service.getOrder("o_100");| Option | Type | Default | Description |
|---|---|---|---|
level |
"debug" | "info" | "warn" | "error" |
"info" |
Minimum log level |
format |
"auto" | "pretty" | "json" |
"auto" |
Output format (auto picks pretty unless NODE_ENV=production) |
output |
logger-like object | console |
Destination with info/warn/error/debug/log or .write() |
redact |
string[] |
sensible defaults | Case-insensitive key masking list |
context |
Record<string, unknown> |
{} |
Global fields merged into each event |
onError |
callback | undefined |
Hook invoked when wrapper/middleware catches errors |
silent |
boolean |
false |
Disable log output entirely |
pilot(fn)creates a thin wrapper around your function.- On invocation, it captures start time + context.
- On success/failure, it emits one structured event with metadata.
- Formatter renders event as pretty text or JSON.
- Output is written to configured destination.
logpilot is intentionally lightweight (zero runtime dependencies). It adds small wrapper overhead from timing, serialization, and output I/O. For latency-sensitive paths, prefer JSON output and conservative payload sizes.
- No built-in log shipping (expects host platform/collector)
- Redaction is key-based (not full PII detection)
- Middleware helper targets common Express/Fastify request shapes
- Optional custom serializer hooks
- Additional middleware adapters with typed helpers
- Extended docs for high-throughput production setups
- License: MIT
- Changelog: CHANGELOG.md
- npm: https://www.npmjs.com/package/@darksol/logpilot
- Issues: https://github.com/darks0l/logpilot/issues
