Zero-dependency structured JSON logger for TypeScript with scoped events, log levels, timing, and console, PostHog and test outputs for Node.js and Convex.
node_modules/@vllnt/logger/docs/API.md documents every export with its signature, and the TypeScript
sources ship in node_modules/@vllnt/logger/src/. Both match the installed version.
- Use it when you want one JSON line per event, with a scoped event name (
auth.login), from TypeScript. - Use it when the same logger API must run in Node.js and in Convex queries, mutations and actions.
- Use it when log entries should go to several outputs, such as the console and PostHog.
- Use it when tests should assert on log entries instead of console output.
- Do not use it when you need log transports, files, rotation, redaction or async batching: use pino or winston.
- Do not use it when entries must be stored and queried later: use
@vllnt/convex-events. - Do not use it for product analytics with consent: use
@vllnt/analytics.
pnpm add @vllnt/loggerimport { createBackendLogger } from "@vllnt/logger";
const logger = createBackendLogger("auth");
logger.warn("login.failed", { userId: "123" });
// console.warn: {"userId":"123","event":"auth.login.failed","level":"warn","timestamp":"2026-11-27T12:00:00.000Z"}createBackendLogger writes warn and error by default. Set LOG_LEVEL=info or LOG_LEVEL=debug to see more.
Full reference with signatures and examples: docs/API.md.
| Export | Import from | What it does |
|---|---|---|
createBackendLogger |
@vllnt/logger |
Node.js logger: level from LOG_LEVEL (default warn), writes with consoleOutput |
createLogger |
@vllnt/logger |
Logger with your own getLogLevel and output |
createExtendedLogger |
@vllnt/logger |
createLogger plus withTiming and withTimingSync |
consoleOutput |
@vllnt/logger |
Output that writes one JSON line to console.debug/info/warn/error |
composeOutputs |
@vllnt/logger |
Combines outputs; a throwing output does not stop the others |
formatLogEntry |
@vllnt/logger |
Builds a LogEntry without a scope prefix |
parseLogLevel |
@vllnt/logger |
Parses a string to a LogLevel, with a default |
LogLevel |
@vllnt/logger |
Type: "debug" | "info" | "warn" | "error" |
LogData |
@vllnt/logger |
Type: Record<string, unknown> passed to a log call |
LogEntry |
@vllnt/logger |
Type: { event, level, timestamp } plus your data |
LogOutput |
@vllnt/logger |
Type: (entry: LogEntry) => void |
Logger |
@vllnt/logger |
Type: debug, info, warn, error methods |
ExtendedLogger |
@vllnt/logger |
Type: Logger plus withTiming, withTimingSync |
LoggerConfig |
@vllnt/logger |
Type: { getLogLevel, output } |
createConvexLogger |
@vllnt/logger/convex |
Convex logger with a fixed level (default info); no process.env |
createPostHogOutput |
@vllnt/logger/posthog |
Output that calls your PostHog capture function |
PostHogCapture |
@vllnt/logger/posthog |
Type: (event, properties?) => unknown |
createTestOutput |
@vllnt/logger/testing |
Output that stores entries in memory for assertions |
TestOutput |
@vllnt/logger/testing |
Type: { entries, output } |
Set the level of createBackendLogger at runtime (read on every log call):
LOG_LEVEL=debug node app.jsUse your own level and output:
import { consoleOutput, createLogger, parseLogLevel } from "@vllnt/logger";
const logger = createLogger("api", {
getLogLevel: () => parseLogLevel(process.env.API_LOG_LEVEL, "info"),
output: consoleOutput,
});
logger.info("request", { method: "GET", path: "/health" });Time an async call. It logs <scope>.<label>.start, then .complete with durationMs, or .error and rethrows:
import { consoleOutput, createExtendedLogger } from "@vllnt/logger";
const logger = createExtendedLogger("db", { getLogLevel: () => "info", output: consoleOutput });
const rows = await logger.withTiming("query", async () => [{ id: 1 }], { table: "users" });
logger.info("rows", { count: rows.length });Log from a Convex query, mutation or action:
import { createConvexLogger } from "@vllnt/logger/convex";
const logger = createConvexLogger("orders", "debug");
logger.info("created", { orderId: "o_1" });Write to the console and to PostHog (posthog-node):
import { composeOutputs, consoleOutput, createLogger } from "@vllnt/logger";
import { createPostHogOutput } from "@vllnt/logger/posthog";
import { PostHog } from "posthog-node";
const client = new PostHog("phc_project_api_key");
const logger = createLogger("billing", {
getLogLevel: () => "info",
output: composeOutputs(
consoleOutput,
createPostHogOutput((event, properties = {}) =>
client.capture({ distinctId: "server", event, properties }),
),
),
});
logger.info("invoice.paid", { invoiceId: "in_1" });
await client.shutdown();Log calls never throw. These are the error messages and markers you can see, and their fixes:
| Error or message | Cause | Fix |
|---|---|---|
[logger:serialize-error] event=<event> level=<level> written instead of JSON |
consoleOutput could not serialize the entry: a nested value has a throwing toJSON (a toJSON function at the top level of the data is skipped), a nested object has a throwing getter, or the data is nested thousands of levels deep. A field of this line that cannot be read is left out |
Log plain, shallow data; convert class instances before logging |
"[Circular]" as a field value |
The data has a circular reference | None needed; log a plain copy to keep the full value |
"error": "[unprintable error]" in a <label>.error entry |
withTiming caught a value whose conversion to a string throws |
Throw Error instances |
The error from your function, after a <label>.error entry |
withTiming and withTimingSync rethrow the original error |
Catch it around the withTiming call |
ERR_PACKAGE_PATH_NOT_EXPORTED from require("@vllnt/logger") |
The package is ESM only and has no require export. A CommonJS project built with moduleResolution: nodenext type-checks, but its output calls require and fails here at runtime |
Use import; in CommonJS use await import("@vllnt/logger"), a .mts file, or "type": "module" |
TS2307: Cannot find module '@vllnt/logger' (TypeScript 6 reports TS5107, node10 is deprecated, first) |
TypeScript moduleResolution is node10 (node), which ignores exports |
Set moduleResolution to nodenext, node16 or bundler |
TS1479: The current file is a CommonJS module whose imports will produce 'require' calls |
A CommonJS file under node16 imports this ESM package |
Add "type": "module", use a .mts file, or use await import() |
createBackendLoggerdefaults towarn:debugandinfocalls write nothing untilLOG_LEVELis set.withTiminglogs.startand.completeatinfo, so only.errorshows at the default.createConvexLoggeruses its fixedlevel(defaultinfo) and never reads environment variables.- An invalid
LOG_LEVELfalls back towarn. A customgetLogLevelthat returns an invalid value or throws falls back toinfo. - Data keys
event,levelandtimestampare silently replaced by the logger's values. formatLogEntrydoes not add the scope prefix; only logger methods do.- A throwing output is swallowed without a trace. Outputs are synchronous: a returned promise is not awaited.
createPostHogOutputswallows rejected promises, but a promise rejected by any other output is not handled; in Node.js that is an unhandled rejection, so catch inside an async output. composeOutputscalls outputs in order, each with the same entry object, so an output must not mutate the entry. A throwing output does not stop the next one.- A throwing getter at the top level of log-call data, or of
withTiming/withTimingSyncextraData, drops that entry silently: it runs while the entry is built. The timing helpers still return the result or rethrow the original error. A throwing getter deeper down gives the[logger:serialize-error]line. consoleOutputwritesBigIntas a string and anError, also one from another realm such asnode:vm, as its own enumerable fields (such ascodeanderrno) plusname,messageandstack. LikeJSON.stringify, it writesMapandSetas{}andNaNasnull; it dropsundefined, functions and symbols from objects and writes them asnullin arrays. AtoJSONfunction at the top level of the data is skipped, so it cannot replace the line;createPostHogOutputlikewise leaves it out of the properties.withTiminglogserror.messageverbatim, without the stack. There is no redaction.withTimingandwithTimingSyncreplaceextraData.durationMsin.completeand.error, andextraData.errorin.error;.startlogsextraDataunchanged.createTestOutputkeeps every entry in memory; create a new one per test.
- Runtime dependencies: none. Peer dependencies: none.
- ESM only, with typings for every entry point. TypeScript
moduleResolutionmust benodenext,node16orbundler, and the importing file must be ESM: in a CommonJS project,nodenexttype-checks but the emittedrequirefails at runtime. - Node.js: no
enginesfield. The build targets ES2024; CI tests on Node.js 24. - Convex:
@vllnt/logger/convexdoes not readprocess.env. Browsers and edge runtimes: the core uses no Node.js APIs andcreateBackendLoggerchecks forprocessfirst, but tests run only on Node.js. - PostHog: with posthog-js, pass
(event, properties) => posthog.capture(event, properties)socapturekeeps itsthis. posthog-node needs the wrapper shown above; it is type-checked against posthog-node 6.
Capture entries with createTestOutput and assert on them:
import assert from "node:assert/strict";
import { createLogger } from "@vllnt/logger";
import { createTestOutput } from "@vllnt/logger/testing";
const { entries, output } = createTestOutput();
const logger = createLogger("checkout", { getLogLevel: () => "debug", output });
logger.info("paid", { orderId: "o_1" });
assert.equal(entries[0]?.event, "checkout.paid");There is no built-in redaction: pass only data you are willing to log. Report vulnerabilities as described in SECURITY.md.
None. This package has no runtime or peer dependencies, and no other @vllnt package shares code, a test or an example with it.
See CONTRIBUTING.md. Every publish runs in
.github/workflows/publish.yml with npm trusted publishing and provenance; nothing is published from a
local machine. Maintainers only.
- Canary (
@canary): every push tomain, or a manual run onmain, publishes one (pnpm add @vllnt/logger@canary). - Stable (
@latest): merge a PR that setspackage.jsonversionand adds a matching## [X.Y.Z]entry toCHANGELOG.md, then push the tagvX.Y.Zon thatmaincommit.
- Docs and changelog: oss.vllnt.com/packages/logger · release feed
- All @vllnt packages: oss.vllnt.com · search packages and docs on index.vllnt.com
- Source and issues: GitHub · issues · npm
- Questions and updates: Discord · X @bntvllnt
- Company and author: vllnt.com · bntvllnt.com · GitHub @bntvllnt · LinkedIn
- Sponsor: GitHub Sponsors
Part of vllnt open source · Package page · vllnt.com · Built by bntvllnt