Skip to main content
This guide provides in-depth information about each method in the BeagleLogPlugin class, including usage patterns and real-world examples.

canHandle()

The canHandle() method is a TypeScript type guard that determines whether a plugin can handle a specific log type.

Type Guard Pattern

The return type log 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 uses instanceof to check the log type:

Examples

MessageLogPlugin:
ErrorLogPlugin:

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 items
  • TabBarContent - Multiple tabs, each containing a list

Content Types

You can use various content types in the returned structure:
  • TextContent - Display text with optional formatting
  • JsonContent - Display JSON data with expand/collapse
  • LabelContent - Display label-value pairs
  • SectionContent - Collapsible sections with children
  • LoadingContent - Loading indicators

Examples

Simple Message Display:
Error with Stack Trace:

provideCardFooter()

Provides optional footer content displayed on the log card in the list view.

Default Behavior

The default implementation returns null, 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:
No Footer (Default):

exportToJSON()

Customizes how logs are exported to JSON format.

Default Behavior

The default implementation uses JSON.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 parameter T 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