Plugin Architecture
Every Beagle plugin consists of two parts:- Log Class: Extends
BeagleLogto store your custom data - Plugin Class: Extends
BeagleLogPluginto handle and display the log
Step-by-Step Guide
We’ll create an analytics plugin that tracks events and parameters, using the actual implementation from the Beagle example app.1
Create the Log Class
First, create a class that extends The constructor calls
BeagleLog to hold your custom data:super() with:- A message that appears in the log list
- A log level (
'info','error','warning', etc.)
2
Extend BeagleLogPlugin
Create a plugin class that extends
BeagleLogPlugin:3
Implement canHandle
The This uses TypeScript’s type guard to check if the log is an instance of your custom log class.
canHandle method determines if this plugin can handle a given log:4
Implement provideDetailContent
The This creates a list view with:
provideDetailContent method defines how your log appears in the detail view:- A label showing the event name
- A bold text header for “Parameters”
- A JSON tree view of the event parameters
5
Register the Plugin
Register your plugin with Beagle before logging any data:
6
Use Your Custom Log
Now you can log analytics events throughout your app:
Optional: Customize the Card Footer
You can also customize how logs appear in the list view by implementingprovideCardFooter:
Complete Working Example
Here’s the complete implementation with both files:Plugin Best Practices
Tips for Building Plugins
- Keep log messages concise: The message appears in the list view, so make it scannable
- Use appropriate log levels: This helps with visual filtering in the inspector
- Structure detail content logically: Group related information using sections
- Leverage content types: Use
json,label,section, andtextto create rich views - Add card footers for key metrics: Show important data without opening the detail view
Advanced: Custom Export
You can customize how logs are exported by overridingexportToJSON: