Logger Service

class LoggerService

This service is a wrapper for communicating with window.console, which manages the browser logger.

It is explicitly integrated with all classes for logging instantiations. It also allows logging errors, warnings and messages. The filters in the browser console can be adjusted to hide or show specific logs.

Browser console with verbose logging disabled
Browser console with verbose logging disabled
Browser console with verbose logging enabled
Browser console with verbose logging enabled

Recipe: Integrate this service with an APM (Application Performance Management) or observability service to upload logs for analysis.

logger.service.ts
@Injectable({
  providedIn: 'root',
})
export class LoggerService {
  private readonly _isLoggingEnabled = inject(IS_LOGGING_ENABLED);

  public constructor() {
    // Buy to unlock
  }

  public logComponentInitialization(componentName: string): void {
    // Buy to unlock
  }

  public logDirectiveInitialization(directiveName: string): void {
    // Buy to unlock
  }

  public logError(error: unknown): void {
    // Buy to unlock
  }

  public logMessages(...messages: unknown[]): void {
    // Buy to unlock
  }

  public logServiceInitialization(serviceName: string): void {
    // Buy to unlock
  }

  public logWarning(warning: string): void {
    // Buy to unlock
  }
}

Last updated