Log methods
The same call shapes are accepted by built-in and custom levels.
trace()debug()info()warn()error()fatal()log(level, ...args)isLevelEnabled(level)@swarmmachina/swm-logs v0.1.1
Structured JSON logger
A zero-runtime-dependency structured JSON logger for Node.js. Every call writes one NDJSON line to stdout, stderr, a file descriptor, a writable destination, or a lifecycle-aware transport.
Choose swm-logs when you need a stable event format, pino-compatible severities, safe serialization and secret redaction, cheap child loggers, and explicit delivery control without bundled network clients.
npm install @swarmmachina/swm-logsimport Logger from '@swarmmachina/swm-logs'
const logger = new Logger({
bindings: { service: 'gateway' },
redact: ['req.headers.authorization']
})
const requestLogger = logger.child({ requestId: 'r1' })
requestLogger.info({ port: 3000 }, 'listening')
requestLogger.error(new Error('request failed'))
await logger.close()| Environment | Status | Note |
|---|---|---|
| Node.js 22 / 24 | Supported | Other major versions are rejected by the engine constraint. |
| Native ESM | Supported | Default and named Logger exports with TypeScript declarations. |
| CommonJS require() | Unsupported | Use import from an ESM application. |
| Runtime dependencies | 0 | Network clients, rotation, and vendor exporters are not bundled. |
| stdout / stderr / fd / writable | Supported | Selected through destination; immediate output is enabled by default. |
| Application transports | Supported | A transport owns its queue, retry, backpressure, persistence, and metrics. |
| Bundled network transports | Not included | HTTP, database, and vendor delivery stay application-owned. |
The same call shapes are accepted by built-in and custom levels.
trace()debug()info()warn()error()fatal()log(level, ...args)isLevelEnabled(level)Threshold control, child bindings, and effective context snapshots.
levelchild(bindings, options)bindings()Operations on the output state shared by a root logger and its children.
flush()flushSync()close()deliveryStats()Levels, serialization, redaction, extensions, and output ownership.
customLevelsserializersredacthooksformatterbufferingdestinationtransportsThe logger class, levels, console bridge, and TypeScript contracts.
LoggerNamedLoggerConsoleBridgeLEVELSLoggerOptionsLogTransportDeliveryStatsComplete signatures, types, and examples are available in the source repository README and TypeScript declarations.
The logger separates event formatting from delivery ownership. The application must choose explicit memory bounds, durability, and the point at which the root logger closes.
When process.stdout.write() returns false, the Node.js stream owns the pending bytes and logging continues. Use a transport with a bounded queue when a strict limit is required.
write(line, level) must accept quickly. Queueing, batching, retries, overflow, persistence, timeouts, and asynchronous failure metrics belong to the transport implementation.
Child loggers share the root lifecycle. Stop accepting work, drain in-flight operations, and then call await rootLogger.close().
Call flushSync() for a fatal exception. Guaranteed durability requires a regular file or numeric descriptor; a generic writer must provide its own guarantee.
Buffering defaults to 64 KiB, 1000 ms, and warn as flushLevel. One oversized record can temporarily exceed maxBytes; the buffer resets after a write attempt.
Destination and synchronous transport failures do not escape a log method. Export onDestinationError and deliveryStats() through an independent observability path.
Prefer exact redact paths for known schemas and use wildcards only for genuinely dynamic structure. Caller-owned data is not mutated.
Numeric severities are pino-compatible, but the surface is intentionally smaller: base becomes bindings, custom levels use log(), and workers, pretty printing, and vendor transports are not bundled.
// pino
const previous = pino({ level: 'info', base: { service: 'gateway' } })
// swm-logs
const logger = new Logger({
level: 'info',
bindings: { service: 'gateway' }
})