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()
message(any, optional): The primary message to logoptionalParams(…any[]): Additional parameters to include in the log output
void
Example:
info()
message(any, optional): The primary message to logoptionalParams(…any[]): Additional parameters to include in the log output
void
Example:
warning()
message(any, optional): The primary message to logoptionalParams(…any[]): Additional parameters to include in the log output
void
Example:
error()
message(any, optional): The primary message to logoptionalParams(…any[]): Additional parameters to include in the log output
void
Example:
write()
level(LogLevel): The log level for this messagemessage(any, optional): The primary message to logoptionalParams(…any[]): Additional parameters to include in the log output
void
Example:
measure()
performance.measure to log a performance measurement.
Parameters:
start(DOMHighResTimeStamp): Start time of the measurementtrackGroup(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 measurementproperties([string, any][], optional): Additional properties to include
PerformanceMeasure - The performance measurement object
Example:
mark()
performance.mark to log a performance mark.
Parameters:
name(string): Name of the mark to create
PerformanceMark - The performance mark object
Example:
ConsoleLogService
A concrete implementation of LogService that outputs to the browser console.Interface
Constructor
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
Behavior
- Debug logs: Only output when
isDevistrue - 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
Debug(0): Detailed diagnostic information for developmentInfo(1): General informational messagesWarning(2): Warning messages for non-critical issuesError(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
trackGroupvalues for team ownership - Use class names for
trackto organize measurements - Include relevant properties to add context to measurements
- Mark significant milestones in long-running operations