Skip to content

Winston

Ship Winston log records to AxonPush as OpenTelemetry-shaped app.log events. Winston is the legacy Node.js logging standard, still widely used.

[!TIP] Non-blocking by default (v0.0.2+)

The transport pushes each record onto a bounded in-memory queue and drains it from a single background task. Call transport.flushAxonPush(timeoutMs?) at known checkpoints to guarantee delivery, or use flushAfterInvocation. Pass mode: "sync" for blocking publishes. See the Pino page for the Lambda flush pattern — flushAfterInvocation works with the Winston transport too.

Terminal window
npm install @axonpush/sdk winston winston-transport

The factory returns a Promise<Transport> because winston-transport is lazily imported (it’s an optional peer dep). Await it before building the logger:

import winston from "winston";
import { AxonPush } from "@axonpush/sdk";
import { createAxonPushWinstonTransport } from "@axonpush/sdk/integrations/winston";
const client = new AxonPush({
apiKey: process.env.AXONPUSH_API_KEY!,
tenantId: process.env.AXONPUSH_TENANT_ID!,
});
const axonpushTransport = (await createAxonPushWinstonTransport({
client,
channelId: 1,
serviceName: "my-api",
environment: "production",
})) as winston.transport;
const log = winston.createLogger({
level: "info",
transports: [new winston.transports.Console(), axonpushTransport],
});
log.info({ message: "user signed in", userId: 42, method: "oauth" });
log.warn({ message: "rate limit approaching", endpoint: "/api/search", remaining: 3 });
log.error({ message: "downstream timeout", endpoint: "/api/search", elapsedMs: 5000 });
interface AxonPushTransport {
flushAxonPush(timeoutMs?: number): Promise<void>;
close(): void;
}
await (axonpushTransport as unknown as AxonPushTransport).flushAxonPush(1000);

close() is called by Winston’s own shutdown lifecycle when you call log.close(); it also runs automatically via the module-level beforeExit hook at process shutdown.

Winston levelOTel severityNumberseverityText
silly, trace1TRACE
debug, verbose5DEBUG
http, info9INFO
notice11INFO
warn, warning13WARN
error17ERROR
crit, alert, emerg, fatal21FATAL
FieldValue
identifier"winston"
eventType"app.log"
payload.bodyThe message field
payload.attributesAll non-standard fields from the Winston info object
payload.resourceservice.name, service.version, deployment.environment (if configured)