MCPcopy
hub / github.com/angular/angular / DebugHandler

Class DebugHandler

packages/service-worker/worker/src/debug.ts:21–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21export class DebugHandler implements DebugLogger {
22 // There are two debug log message arrays. debugLogA records new debugging messages.
23 // Once it reaches DEBUG_LOG_BUFFER_SIZE, the array is moved to debugLogB and a new
24 // array is assigned to debugLogA. This ensures that insertion to the debug log is
25 // always O(1) no matter the number of logged messages, and that the total number
26 // of messages in the log never exceeds 2 * DEBUG_LOG_BUFFER_SIZE.
27 private debugLogA: DebugMessage[] = [];
28 private debugLogB: DebugMessage[] = [];
29
30 constructor(
31 readonly driver: Debuggable,
32 readonly adapter: Adapter,
33 ) {}
34
35 async handleFetch(req: Request): Promise<Response> {
36 const [state, versions, idle] = await Promise.all([
37 this.driver.debugState(),
38 this.driver.debugVersions(),
39 this.driver.debugIdleState(),
40 ]);
41
42 const msgState = `NGSW Debug Info:
43
44Driver version: ${SW_VERSION}
45Driver state: ${state.state} (${state.why})
46Latest manifest hash: ${state.latestHash || 'none'}
47Last update check: ${this.since(state.lastUpdateCheck)}`;
48
49 const msgVersions = versions
50 .map(
51 (version) => `=== Version ${version.hash} ===
52
53Clients: ${version.clients.join(', ')}`,
54 )
55 .join('\n\n');
56
57 const msgIdle = `=== Idle Task Queue ===
58Last update tick: ${this.since(idle.lastTrigger)}
59Last update run: ${this.since(idle.lastRun)}
60Task queue:
61${idle.queue.map((v) => ' * ' + v).join('\n')}
62
63Debug log:
64${this.formatDebugLog(this.debugLogB)}
65${this.formatDebugLog(this.debugLogA)}
66`;
67
68 return this.adapter.newResponse(
69 `${msgState}
70
71${msgVersions}
72
73${msgIdle}`,
74 {headers: this.adapter.newHeaders({'Content-Type': 'text/plain'})},
75 );
76 }
77
78 since(time: number | null): string {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…