| 505 | * Observes log messages from an RazorLogger and collects them until disposed. |
| 506 | */ |
| 507 | export class RazorLogObserver { |
| 508 | private readonly _messages: Message[] = []; |
| 509 | private readonly _subscription: vscode.Disposable; |
| 510 | |
| 511 | constructor(logger: RazorLogger) { |
| 512 | this._subscription = logger.onLog((message) => { |
| 513 | this._messages.push({ message, timestamp: new Date() }); |
| 514 | }); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Returns the collected messages as a formatted string suitable for a log file. |
| 519 | */ |
| 520 | public getLog(): string { |
| 521 | return RazorLogObserver.formatLogMessages(this._messages); |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Disposes the subscription and stops observing log messages. |
| 526 | */ |
| 527 | public dispose(): void { |
| 528 | this._subscription.dispose(); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Formats an array of log messages into a string suitable for a log file. |
| 533 | */ |
| 534 | public static formatLogMessages(messages: Message[]): string { |
| 535 | return messages |
| 536 | .map((msg) => { |
| 537 | const timestamp = msg.timestamp.toISOString(); |
| 538 | return `[${timestamp}] ${msg.message}`; |
| 539 | }) |
| 540 | .join('\n'); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Creates an activity log capture that collects logs from the C#, LSP trace, and Razor channels. |
nothing calls this directly
no outgoing calls
no test coverage detected