Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ency07/B2B/llms.txt

Use this file to discover all available pages before exploring further.

The logger (src/lib/utils/logger.ts) is a lightweight structured logging utility. In development it prints to the console with level, timestamp, and module tag. In production you replace the transport with Sentry, Datadog, or any external service by calling setTransport().
Never use console.error(), console.log(), or similar raw calls in production code. Always use the module logger so logs include the module tag and can be routed to the correct external service.

API Reference

createLogger(module) — default export

Creates a scoped logger for a given module. Each log call automatically includes the module name, ISO timestamp, and any extra metadata passed as options.
import createLogger from "@/lib/utils/logger";

const logger = createLogger("wizard");

logger.debug("Calculating CFM", { data: { length: 50, width: 30 } });
logger.info("Lead created", { tenantId: "a0000000-..." });
logger.warn("Tenant not found, using default", { module: "tenant-resolver" });
logger.error("Invoice creation failed", { error: new Error("RLS violation") });
The returned logger object has the following type:
type Logger = {
  debug: (message: string, opts?: Partial<LogEntry>) => void;
  info:  (message: string, opts?: Partial<LogEntry>) => void;
  warn:  (message: string, opts?: Partial<LogEntry>) => void;
  error: (message: string, opts?: Partial<LogEntry>) => void;
  child: (childModule: string) => Logger;
};
This type is also exported as Logger (export type Logger = ReturnType<typeof createLogger>).

Convenience Functions (root logger)

logError and logWarn are pre-bound to the root "app" logger. Use them in utilities or top-level error boundaries where creating a named logger is unnecessary.
import { logError, logWarn } from "@/lib/utils/logger";

logError("Critical error", { error: new Error("...") });
logWarn("Unexpected state", { data: { key: "value" } });

Child Loggers

Call .child(subModule) on any logger to create a namespaced child. The resulting module tag is "parent:child", which makes it easy to filter logs by subsystem.
const logger = createLogger("platform");
const authLogger = logger.child("auth"); // module = "platform:auth"

setTransport(fn) — Custom Transport for Production

Replace the default console transport with any function that accepts a LogEntry. Call this once at application startup (e.g., in instrumentation.ts).
import { setTransport } from "@/lib/utils/logger";
import * as Sentry from "@sentry/nextjs";

setTransport((entry) => {
  if (entry.level === "error") {
    Sentry.captureException(entry.error ?? new Error(entry.message), {
      extra: entry.data,
      tags: { module: entry.module },
    });
  }
  // also write to console in non-prod
  if (process.env.NODE_ENV !== "production") {
    console[entry.level](`[${entry.module}] ${entry.message}`, entry.data);
  }
});

LogEntry Interface

Every call to any logger method constructs and passes a LogEntry to the active transport.
interface LogEntry {
  level: "debug" | "info" | "warn" | "error";
  message: string;
  module: string;
  timestamp: string;           // ISO 8601
  data?: Record<string, unknown>;
  error?: Error;
  requestId?: string;
  tenantId?: string;
}
FieldTypeDescription
level"debug" | "info" | "warn" | "error"Severity level
messagestringHuman-readable log message
modulestringModule tag set in createLogger()
timestampstringISO 8601 timestamp generated at log time
dataRecord<string, unknown>Optional structured metadata
errorErrorOptional error object (stack trace included by default transport)
requestIdstringOptional request correlation ID
tenantIdstringOptional tenant identifier for multi-tenant tracing

Build docs developers (and LLMs) love