CxJS

Console

import { Console } from 'cx/util'; Copied

The Console utility provides safe console logging methods that only execute when running in a browser environment with console support.

Basic Usage

import { Console } from "cx/util";

Console.log("Debug message");
Console.warn("Warning message");
Console.error("Error message");

Why Use This?

The Console utility safely handles environments where window or console may not be available, such as during server-side rendering or in older browsers.

// Standard console - may throw in SSR
console.log("message"); // Error if window is undefined

// Safe console - no-op in SSR
Console.log("message"); // Works everywhere

Methods

Console.log

Console.log("User logged in:", userId);
Console.log({ data: response });

Console.warn

Console.warn("Deprecated API usage");
Console.warn("Missing optional config:", configKey);

Console.error

Console.error("Failed to load data:", error);
Console.error("Invalid state:", state);

API

const Console = {
  log: (...args: any[]) => void;
  warn: (...args: any[]) => void;
  error: (...args: any[]) => void;
};

All methods accept any number of arguments, matching the native console API.