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 useflushAfterInvocation. Passmode: "sync"for blocking publishes. See the Pino page for the Lambda flush pattern —flushAfterInvocationworks with the Winston transport too.
Installation
Section titled “Installation”npm install @axonpush/sdk winston winston-transportThe 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 });Flushing and closing
Section titled “Flushing and closing”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.
Level mapping
Section titled “Level mapping”| Winston level | OTel severityNumber | severityText |
|---|---|---|
silly, trace | 1 | TRACE |
debug, verbose | 5 | DEBUG |
http, info | 9 | INFO |
notice | 11 | INFO |
warn, warning | 13 | WARN |
error | 17 | ERROR |
crit, alert, emerg, fatal | 21 | FATAL |
Events
Section titled “Events”| Field | Value |
|---|---|
identifier | "winston" |
eventType | "app.log" |
payload.body | The message field |
payload.attributes | All non-standard fields from the Winston info object |
payload.resource | service.name, service.version, deployment.environment (if configured) |