Skip to content

Console

Wraps console operations in Effect.

The Console service exposes common console methods such as logging, warnings, errors, groups, counters, tables, and timers. Because console access goes through a service, programs can use custom console implementations in tests or other environments. This module also includes scoped helpers that close console groups or timers automatically.

21 exports Added in v2.0.0 Source

Accessors

assert

Added in v2.0.0 Source

Writes the supplied assertion message to the console as an error when condition is false; when condition is true, no console output is produced.

Signature

declare function assert(condition: boolean, ...args: readonly Array<any>): Effect<void>

clear

Added in v2.0.0 Source

Runs the current console service's clear operation.

When to use

Use to request that the active console implementation clear its visible output.

Gotchas

The clearing behavior depends on the active console implementation and host environment.

Signature

declare const clear: Effect.Effect<void>;

count

Added in v2.0.0 Source

Logs and increments the counter associated with label, using the console's default counter when no label is provided.

Signature

declare function count(label?: string): Effect<void>;

countReset

Added in v2.0.0 Source

Resets the counter associated with the specified label back to zero.

Signature

declare function countReset(label?: string): Effect<void>;

debug

Added in v2.0.0 Source

Writes a debug message through the current Console service.

Details

The arguments are passed to the service's debug method when the returned Effect is executed. Any filtering behavior depends on the active console implementation.

Signature

declare function debug(...args: readonly Array<any>): Effect<void>

dir

Added in v2.0.0 Source

Displays an interactive list of the properties of the specified object, optionally using console-specific inspection options for debugging complex data structures.

Signature

declare function dir(item: any, options?: any): Effect<void>;

dirxml

Added in v2.0.0 Source

Displays an interactive tree of descendant XML or HTML elements, which is particularly useful for inspecting DOM elements in browser environments.

Signature

declare function dirxml(...args: readonly Array<any>): Effect<void>

error

Added in v2.0.0 Source

Writes an error-level message to the console, typically displayed with error styling by the active console implementation.

Signature

declare function error(...args: readonly Array<any>): Effect<void>

group

Added in v2.0.0 Source

Creates a scoped console group, optionally collapsed and labeled, and closes it automatically when the Effect scope is finalized.

Signature

declare function group(options?: {
  collapsed?: boolean;
  label?: string;
}): Effect<void, never, Scope>;

info

Added in v2.0.0 Source

Writes an informational message to the console, typically displayed with info styling by the active console implementation.

Signature

declare function info(...args: readonly Array<any>): Effect<void>

log

Added in v2.0.0 Source

Logs a general-purpose message to the console.

Signature

declare function log(...args: readonly Array<any>): Effect<void>

table

Added in v2.0.0 Source

Displays tabular data as a formatted table in the console, optionally limited to selected properties.

Signature

declare function table(tabularData: any, properties?: readonly Array<string>): Effect<void>

time

Added in v2.0.0 Source

Starts a scoped timer for label and automatically ends it when the Effect scope is finalized.

Signature

declare function time(label?: string): Effect<void, never, Scope>;

timeLog

Added in v2.0.0 Source

Logs the elapsed time for an existing timer without stopping it, allowing progress reports for long-running operations.

Signature

declare function timeLog(label?: string, ...args: readonly Array<any>): Effect<void>

trace

Added in v2.0.0 Source

Writes the current stack trace to the console to show how the current point in the code was reached.

Signature

declare function trace(...args: readonly Array<any>): Effect<void>

warn

Added in v2.0.0 Source

Writes a warning-level message to the console, typically displayed with warning styling by the active console implementation.

Signature

declare function warn(...args: readonly Array<any>): Effect<void>

withGroup

Added in v2.0.0 Source

Runs an Effect inside an optionally labeled or collapsed console group, starting the group before execution and ending it after the Effect completes.

Signature

declare const withGroup: (options?: {
  readonly collapsed?: boolean;
  readonly label?: string;
}) => <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R> & <A, E, R>(self: Effect<A, E, R>, options?: {
  readonly collapsed?: boolean;
  readonly label?: string;
}) => Effect<A, E, R>

withTime

Added in v2.0.0 Source

Runs an Effect with a console timer, starting the timer before execution and ending it after the Effect completes.

Signature

declare const withTime: (label?: string) => <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R> & <A, E, R>(self: Effect<A, E, R>, label?: string) => Effect<A, E, R>

Constructors

consoleWith

Added in v2.0.0 Source

Creates an Effect that provides access to the current console service and lets you perform operations with it within an Effect context.

Signature

declare function consoleWith<A, E, R>(f: (console: Console) => Effect<A, E, R>): Effect<A, E, R>;

Services

Console

Added in v2.0.0 Source

Context reference for the current console service in the Effect system, allowing access to the active console implementation from within the Effect context.

When to use

Use when you need an effect to run against a provided console implementation, such as tests or alternate runtimes, rather than the default console.

Details

When no override is provided, the reference resolves to globalThis.console.

See

  • consoleWith for using the current console service inside an effect

Signature

declare const Console: Reference<Console>;

Console interface

Added in v2.0.0 Source

Represents a console interface for logging, debugging, timing, and grouping output.

Signature

interface Console {
  assert(condition: boolean, ...args: readonly Array<any>): void;
  clear(): void;
  count(label?: string): void;
  countReset(label?: string): void;
  debug(...args: readonly Array<any>): void;
  dir(item: any, options?: any): void;
  dirxml(...args: readonly Array<any>): void;
  error(...args: readonly Array<any>): void;
  group(...args: readonly Array<any>): void;
  groupCollapsed(...args: readonly Array<any>): void;
  groupEnd(): void;
  info(...args: readonly Array<any>): void;
  log(...args: readonly Array<any>): void;
  table(tabularData: any, properties?: readonly Array<string>): void;
  time(label?: string): void;
  timeEnd(label?: string): void;
  timeLog(label?: string, ...args: readonly Array<any>): void;
  trace(...args: readonly Array<any>): void;
  warn(...args: readonly Array<any>): void;
}