← All posts

Production patterns for the LoggerMan Node.js SDK

Flush behavior, backpressure, error handling, multi-service layouts, and how to pair the SDK with ingest headers and dashboard triage.

SDKNode.jsProduction

Treat logging as a dependency

The @marvink02/loggerman-sdk is a thin client over our HTTP ingest API. Production reliability comes from **how you call it**, not from log volume alone.

If you have not sent a first event yet, complete Getting started and verify the stream in Dashboard → Logs.

Singleton logger per process

Create one `createLogger` instance per service at module scope. Re-instantiating per request adds overhead and makes custom hooks harder to reason about.

import { createLogger } from "@marvink02/loggerman-sdk";

export const logger = createLogger({ projectId: process.env.LOGGERMAN_PROJECT_ID!, token: process.env.LOGGERMAN_TOKEN!, baseUrl: process.env.LOGGERMAN_BASE_URL!, source: process.env.SERVICE_NAME ?? "api", environment: process.env.NODE_ENV, }); ```

Never block the critical path on logging

`await logger.error(...)` is appropriate in background workers. In hot HTTP handlers, prefer fire-and-forget with explicit error capture:

void logger.error("payment.failed", { code: "CARD_DECLINED" }).catch((e) => {
  console.error("[loggerman] ingest failed", e);
});

If ingest is down, your API should still return a response to users. Monitor ingest health via platform docs and response headers described in API reference.

Stable codes beat prose

Alerts and dashboards group on repeated strings. Use:

  • message: short human summary (`checkout.failed`)
  • metadata.code: machine-stable identifier
  • metadata.orderId, metadata.userId: correlation

This pairs directly with alert rules and CSV export on Team plans (pricing).

Multi-service topology

  • **Monolith** — one project, `source` per module.
  • **Microservices** — one project per product, or per env with distinct `source` values.
  • **Multi-tenant B2B** — never mix tenants on one token; see team access.

Security checklist

  • Rotate tokens after engineer offboarding (API keys).
  • Enable ingest IP allowlists for fixed egress (security settings).
  • Redact PII field keys at ingest — configured in project security, documented in security.

Pair with Winston or Pino

Transports ship in `@marvink02/loggerman-winston` and `@marvink02/loggerman-pino` (see integrations). Keep JSON structure in the record; let the transport map levels to LoggerMan types.

When ingest returns 402 or 429

  • **402 / billing blocked** — owner subscription needs attention; see billing.
  • **429** — respect `Retry-After` and backoff; burst traffic may enter the ingest queue.

Related reading