Skip to content

ReplLogger

reference
1 min readUpdated

Kind: Class

Source: packages/core/repl/repl-logger.ts

Part of: Core

ReplLogger provides logging support for the REPL subsystem, centralizing how messages are emitted during interactive sessions. Its log() method should be used by REPL commands and runtime flows that need to report status, output, or diagnostic information consistently.

Extends: ConsoleLogger

Methods

MethodSignatureReturns
loglog(_message: any, context: string)void

Where it refuses work

  • ReplLogger stops the work with an early return when ReplLogger.ignoredContexts.includes(context!).

Diagram

mermaid
graph LR
  Command[REPL Command] --> Logger[ReplLogger]
  Runtime[REPL Runtime] --> Logger
  Logger --> Output[Interactive Console Output]

Usage

ts
import { ReplLogger } from "./repl-logger";

const logger = new ReplLogger();

logger.log("REPL session started");

// Use the shared logger from command handlers or runtime operations.
function runCommand(command: string) {
  logger.log(`Executing command: ${command}`);
}

runCommand("help");

AI Coding Instructions

  • Use ReplLogger.log() for REPL-facing messages instead of writing directly to the console.
  • Keep logged messages concise and actionable because they are displayed in an interactive terminal context.
  • Reuse the logger instance managed by the REPL runtime when one is available; avoid creating unnecessary per-command instances.
  • Preserve existing output formatting and ordering so command output remains predictable for users and tests.

How it works

ReplLogger

ReplLogger is a ConsoleLogger subclass used when repl() creates a Nest application context. The REPL passes a new instance as the context’s logger option before initializing the application. packages/core/repl/repl-logger.ts:6 packages/core/repl/repl.ts:16-20

It overrides only log; inherited methods such as error, warn, debug, verbose, and fatal are not overridden. packages/core/repl/repl-logger.ts:13-19 packages/common/services/console-logger.service.ts:192-276

Relationships

  • IMPORTS → ConsoleLogger

Was this page helpful?

Download as PDF
ReplLogger — NestJS head-to-head