BeagleLogPlugin class, including usage patterns and real-world examples.
canHandle()
ThecanHandle() method is a TypeScript type guard that determines whether a plugin can handle a specific log type.
Type Guard Pattern
The return typelog is T is a TypeScript type predicate. When this method returns true, TypeScript automatically narrows the type of the log parameter to T in subsequent code.
Implementation Pattern
The typical implementation usesinstanceof to check the log type:
Examples
MessageLogPlugin:provideDetailContent()
Generates the detailed view content when a log is expanded or viewed in detail.Return Type
DetailContent can be either:
ListContent- A simple list of content itemsTabBarContent- Multiple tabs, each containing a list
Content Types
You can use various content types in the returned structure:TextContent- Display text with optional formattingJsonContent- Display JSON data with expand/collapseLabelContent- Display label-value pairsSectionContent- Collapsible sections with childrenLoadingContent- Loading indicators
Examples
Simple Message Display:provideCardFooter()
Provides optional footer content displayed on the log card in the list view.Default Behavior
The default implementation returnsnull, meaning no footer is displayed.
Use Cases
- Display preview text (e.g., first few lines of stack trace)
- Show metadata or additional context
- Display status indicators or badges
Example
Error Stack Preview:exportToJSON()
Customizes how logs are exported to JSON format.Default Behavior
The default implementation usesJSON.stringify() to serialize the entire log object:
Use Cases
- Filter sensitive information before export
- Format data for external tools
- Include additional metadata
- Transform nested objects
Custom Implementation Example
Best Practices
Type Safety
Always use the type parameterT to ensure type safety:
Content Reusability
Extract common content patterns into helper functions:Selectable Content
Make text content selectable when users might want to copy it:See Also
- BeagleLogPlugin - Abstract class reference
- Content Types - Available content structures
- Creating Custom Plugins - Step-by-step guide