Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
logger.ts File Reference

Advanced dual-channel logging system for VS Code extension development. More...

Go to the source code of this file.

Data Structures

class  LoggerInternals
 Core utility infrastructure for logging operations and formatting. More...
 
class  Gui
 User-facing notification system for VS Code extension GUI integration. More...
 
class  Log
 Primary logging controller with dual-channel output and caller identification. More...
 

Variables

import *as vscode from vscode
 
 import { CodeConfig } from "./processConfiguration"
 
const instance = new Log()
 Singleton logger instance for application-wide use.
 
export const logger
 Singleton logger instance providing unified logging interface for the entire extension.
 
export type LogType = Log
 Type alias for Log class enabling dependency injection and testing.
 

Detailed Description

Advanced dual-channel logging system for VS Code extension development.

Author
Henry Letellier
Version
1.0.10
Since
1.0.0
Date
2025

This module implements a sophisticated logging infrastructure designed specifically for VS Code extensions, providing both console output for developers and GUI notifications for end users. The system features automatic caller identification, precise timestamping, configurable output channels, and intelligent debug mode handling.

Architecture Overview: The logging system employs a multi-class architecture with clear separation of concerns:

  • LoggerInternals: Core utility functions for formatting, timing, and stack analysis
  • Gui: User-facing notifications through VS Code's notification API
  • Log: Developer-focused console logging with caller identification
  • Singleton Pattern: Single instance ensures consistent behavior across the extension

Key Features:

  • Dual Output Channels: Console logging for developers, GUI notifications for users
  • Automatic Caller Detection: Stack trace analysis identifies calling functions
  • Precise Timestamping: Millisecond-accurate timestamps for debugging
  • Installation-Aware Logging: Adapts behavior based on development vs production mode
  • Configurable Debug Output: Respects extension debug settings
  • VS Code Output Panel Integration: Dedicated output channel for extension logs
  • Template-based Notifications: Type-safe interactive GUI messages with buttons
  • Comprehensive Log Levels: Info, warning, error, and debug with appropriate console methods

Output Channels:

  1. Console Output: Traditional console.log/warn/error for development debugging
  2. VS Code Output Panel: Structured logs in dedicated extension output channel
  3. GUI Notifications: Toast notifications for user feedback and interaction

Performance Optimizations:

  • Debug GUI notifications are filtered at source when debug mode disabled
  • Stack trace analysis is performed efficiently with configurable depth
  • Output channel reuse prevents resource leaks
  • Conditional console output based on development vs production environment
  • Auto-show output panel only in development for immediate debugging access

Thread Safety: All logging operations are synchronous and thread-safe within VS Code's single-threaded JavaScript environment. No additional synchronization required.

Environment Behavior Summary:

Development Mode (F5 debugging, unpackaged):

  • Console output enabled (console.log/warn/error/debug)
  • Output panel auto-shows for immediate visibility
  • GUI notifications work normally
  • All logging features active for debugging

Production Mode (installed from marketplace):

  • Console output suppressed (clean user experience)
  • Output panel available but hidden by default
  • GUI notifications work normally (primary user feedback)
  • Panel logs preserved for user troubleshooting

Usage Patterns:

import { logger } from './logger';
// Console + Panel logging (visible in dev, panel-only in prod)
logger.info("Operation completed successfully");
logger.error("Failed to process request");
// GUI notifications (always visible to users)
logger.Gui.warning("File not found", "Retry", "Cancel");
logger.Gui.error("Critical error occurred");
// Debug output (conditional based on settings)
logger.debug("Variable state: " + JSON.stringify(data));
logger.Gui.debug("Debug info"); // Only shows if debug enabled

Definition in file logger.ts.

Variable Documentation

◆ import

import { CodeConfig } from "./processConfiguration"

Definition at line 80 of file logger.ts.

◆ instance

const instance = new Log()

Singleton logger instance for application-wide use.

Definition at line 870 of file logger.ts.

◆ logger

export const logger

Singleton logger instance providing unified logging interface for the entire extension.

Primary logging interface exported for application-wide use. This singleton instance ensures consistent logging behavior, formatting, and configuration across all extension modules while providing both developer-focused console output and user-facing GUI notifications.

Singleton Benefits:

  • Consistent Configuration: Single source of truth for logging settings
  • Unified Formatting: Standardized output format across all modules
  • Resource Efficiency: Shared output channels and utility instances
  • State Management: Centralized installation state and debug configuration

Usage Patterns:

import { logger } from './modules/logger';
// Developer console logging
logger.info("Operation completed successfully");
logger.warning("Deprecated API usage detected");
logger.error("Critical failure in component X");
logger.debug("Variable state: " + JSON.stringify(data));
// User GUI notifications
const result = await logger.Gui.info("Save changes?", "Yes", "No", "Cancel");
logger.Gui.warning("File not found, create new?", "Create", "Browse");
logger.Gui.error("Connection failed, check network settings");

Output Destinations:

  1. Console: Development/test debugging only (F12 Developer Tools)
  2. Output Panel: Structured logs in VS Code OUTPUT tab (always available)
  3. Notifications: Toast messages in VS Code interface (user interactions)

Thread Safety: Safe for use from any extension context without additional synchronization. All operations are synchronous and atomic within VS Code's event loop.

Definition at line 910 of file logger.ts.

◆ LogType

export type LogType = Log

Type alias for Log class enabling dependency injection and testing.

Provides a TypeScript type alias for the Log class, facilitating dependency injection patterns, mock implementations for testing, and type-safe interfaces where logger instances need to be passed as parameters or stored as properties.

Use Cases:

  • Dependency Injection: Type-safe logger parameter definitions
  • Testing: Mock logger implementations with compatible interfaces
  • Interface Design: Abstract logger dependencies in class constructors
  • Type Annotations: Explicit typing for logger variables and properties

Example Usage:

class ComponentA {
constructor(private logger: LogType) {}
performOperation() {
this.logger.info("Operation started");
}
}
// Dependency injection
const component = new ComponentA(logger);

Definition at line 940 of file logger.ts.

◆ vscode

import* as vscode from vscode

Definition at line 79 of file logger.ts.