Skip to main content

Overview

The Logging Service provides a unified interface for logging messages, errors, and performance metrics throughout the application. It supports multiple log levels and includes performance measurement capabilities.

LogService

The abstract base class that all logging implementations must extend.

Interface

Methods

debug()

Logs a debug-level message. Typically only shown in development environments. Parameters:
  • message (any, optional): The primary message to log
  • optionalParams (…any[]): Additional parameters to include in the log output
Returns: void Example:

info()

Logs an informational message. Parameters:
  • message (any, optional): The primary message to log
  • optionalParams (…any[]): Additional parameters to include in the log output
Returns: void Example:

warning()

Logs a warning message for non-critical issues. Parameters:
  • message (any, optional): The primary message to log
  • optionalParams (…any[]): Additional parameters to include in the log output
Returns: void Example:

error()

Logs an error message for critical issues and exceptions. Parameters:
  • message (any, optional): The primary message to log
  • optionalParams (…any[]): Additional parameters to include in the log output
Returns: void Example:

write()

Writes a log message at the specified log level. Parameters:
  • level (LogLevel): The log level for this message
  • message (any, optional): The primary message to log
  • optionalParams (…any[]): Additional parameters to include in the log output
Returns: void Example:

measure()

Helper wrapper around performance.measure to log a performance measurement. Parameters:
  • start (DOMHighResTimeStamp): Start time of the measurement
  • trackGroup (string): A track-group for the measurement (generally the team owning the domain)
  • track (string): A track for the measurement (generally the class name)
  • measureName (string): A descriptive name for the measurement
  • properties ([string, any][], optional): Additional properties to include
Returns: PerformanceMeasure - The performance measurement object Example:

mark()

Helper wrapper around performance.mark to log a performance mark. Parameters:
  • name (string): Name of the mark to create
Returns: PerformanceMark - The performance mark object Example:

ConsoleLogService

A concrete implementation of LogService that outputs to the browser console.

Interface

Constructor

Parameters:
  • isDev (boolean): Whether the application is running in development mode (enables debug logs)
  • filter ((level: LogLevel) => boolean | null, optional): Optional filter function to suppress certain log levels
Example:

Behavior

  • Debug logs: Only output when isDev is true
  • Info logs: Output using console.log
  • Warning logs: Output using console.warn
  • Error logs: Output using console.error
  • Performance measurements: Automatically logged with duration information
  • Performance marks: Automatically logged with timestamp

Types

LogLevel

Defines the severity level of log messages.
  • Debug (0): Detailed diagnostic information for development
  • Info (1): General informational messages
  • Warning (2): Warning messages for non-critical issues
  • Error (3): Error messages for critical issues

Usage Examples

Basic Logging

Conditional Logging

Performance Tracking

Custom Log Filtering

Error Handling with Context

Performance Benchmarking

Best Practices

Log Level Selection

  • Use debug() for detailed diagnostic information needed during development
  • Use info() for important runtime events and state changes
  • Use warning() for recoverable issues that may need attention
  • Use error() for failures and exceptions that impact functionality

Structured Logging

Performance Measurement

  • Use consistent trackGroup values for team ownership
  • Use class names for track to organize measurements
  • Include relevant properties to add context to measurements
  • Mark significant milestones in long-running operations