Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pouryazardosht/nestjs-devtools/llms.txt

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

Logger Helper eliminates the tedium of writing this.logger.<method>() boilerplate by hand. Select a variable or expression, press a two-key chord, and the extension inserts a fully formatted log statement on the correct line — automatically embedding the enclosing class name in the message so you always know exactly where a log came from.

How it works

Every logger insertion follows three steps drawn directly from the extension’s source:
  1. Read the selection. The extension reads editor.selection and calls editor.document.getText(selection).trim() to get the selected variable or expression. If nothing is selected, a warning is shown and execution stops.
  2. Detect the enclosing class name. getEnclosingClassName walks upward from the cursor line, testing each line against the regex:
    /^\s*(?:export\s+)?(?:abstract\s+)?class\s+([a-zA-Z_$][\w$]*)/
    
    The first match yields the class name (e.g. UserService). If no class is found, the log message omits the class prefix entirely.
  3. Determine the insertion point. findInsertionLine inspects the line where the selection starts:
    • If that line’s trimmed text does not end with {, the logger is inserted on the very next line.
    • If it does end with { (an opening block), the algorithm counts brace depth — incrementing for every { and decrementing for every } on each subsequent line — until depth reaches 0. The logger is then inserted after that closing } line, safely outside the block.
    The inserted statement inherits the indentation of the selection line, so it aligns naturally with your existing code.

Log methods

Five methods are available, each mapped to an emoji and a dedicated keyboard chord:
MethodEmojimacOS ChordWindows / Linux Chord
debug🔍Cmd+L Cmd+DCtrl+L Ctrl+D
log📝Cmd+L Cmd+LCtrl+L Ctrl+L
warn⚠️Cmd+L Cmd+WCtrl+L Ctrl+W
errorCmd+L Cmd+ECtrl+L Ctrl+E
verbose🔊Cmd+L Cmd+VCtrl+L Ctrl+V

Usage example

Suppose your cursor is inside UserService and you select the identifier user after a findOne call:
// Before: select "user" on the line below, then press Cmd+L Cmd+D
const user = await this.userRepository.findOne({
  where: { email },
  select: { id: true, email: true },
});
After the chord fires:
// After: logger inserted after the closing brace
const user = await this.userRepository.findOne({
  where: { email },
  select: { id: true, email: true },
});
this.logger.debug("🔍 UserService ~ user", user);
The log message format is always "<emoji> <ClassName> ~ <selectedText>", with both the variable name and its runtime value passed to the logger.

Block-aware insertion

When the line where your selection starts ends with {, the extension skips past the entire block and places the logger after the matching closing }.
// Select "user" on the findOne line — it ends with "{"
const user = await this.userRepository.findOne({
  where: { email },
  select: { id: true, email: true },
});
// ↑ Logger is placed here, after the closing brace
this.logger.debug("🔍 UserService ~ user", user);
This block-aware placement means you never accidentally insert a logger statement inside a multi-line argument object or callback — the log always lands in a position where it is valid JavaScript/TypeScript.

Class name detection

getEnclosingClassName scans upward from the cursor line, so it works regardless of how far down inside a class the cursor sits. The regex matches standard class declarations including exported and abstract variants:
// All of these are detected correctly:
export class UserService { ... }
export abstract class BaseRepository { ... }
class AuthGuard { ... }
When the class is AuthGuard, a debug statement on a selected variable token produces:
this.logger.debug("🔍 AuthGuard ~ token", token);
If the cursor is in a plain function or module-level code with no enclosing class, the class prefix is omitted and the message becomes simply "🔍 token".

Requirements

Logger Helper requires an active text selection. If no text is highlighted when you press the chord, VS Code will display a warning — “⚠️ Select a variable or expression first” — and no logger statement will be inserted.

Keyboard Shortcuts

View all logger keybindings

Build docs developers (and LLMs) love