flex_logger_sentry
Send FlexLogger logs to Sentry as breadcrumbs and events for error tracking and crash analytics in Flutter apps.
Contents
Features
- Error tracking – Exceptions/errors in logs trigger
Sentry.captureExceptionvia observer'sonException/onError - Level mapping –
FlexLogLevel.toSentryLevel()extension (success → info, critical → fatal) - Breadcrumbs – All logs that pass the filter are added as breadcrumbs; warning/error/critical also create events (issues)
- Filtering – Default
MinLevelFilter(FlexLogLevel.error); override with anyLogFilter - Sentry options – Optional
optionsConfigurationcallback forSentryFlutterOptions
Installation
Add this to your package's pubspec.yaml file:
dependencies:
flex_logger: ^1.0.0
flex_logger_sentry: ^1.0.0
Then run:
flutter pub get
Setup
1. Get Sentry DSN
First, create a project in Sentry and get your DSN.
2. Basic Setup
import 'package:flex_logger/flex_logger.dart';
import 'package:flex_logger_sentry/flex_logger_sentry.dart';
void main() async {
FlexLogger.instance.configure(
providers: [
SentryLoggerProvider(
dsn: 'YOUR_SENTRY_DSN_HERE',
filter: const MinLevelFilter(FlexLogLevel.warning),
optionsConfiguration: (options) {
options.environment = 'production';
options.release = '1.0.0';
},
),
],
);
await FlexLogger.instance.initialize();
runApp(MyApp());
}
3. Using Different Filters
// Type-based filtering - only specific log types
SentryLoggerProvider(
dsn: 'YOUR_SENTRY_DSN_HERE',
filter: CompositeLogFilter.or([TypeFilter<ErrorLog>(), TypeFilter<CriticalLog>()]),
)
// Composite filtering - combine multiple conditions
SentryLoggerProvider(
dsn: 'YOUR_SENTRY_DSN_HERE',
filter: CompositeLogFilter.and([
MinLevelFilter(FlexLogLevel.warning),
DevelopmentOnlyFilter(), // Only in development
]),
)
Usage
Once configured, logs that pass the provider's filter are sent to Sentry (breadcrumbs and/or events). Use FlexLogger as usual:
import 'package:flex_logger/flex_logger.dart';
void doSomething() {
try {
FlexLogger.instance.info('Operation completed successfully');
} catch (error, stackTrace) {
FlexLogger.instance.error('Operation failed', error, stackTrace);
}
}
Exceptions and errors in logs are captured by the Sentry observer via onException / onError and sent with Sentry.captureException.
Log Level Mapping
| FlexLogger Level | Sentry Level | Behavior |
|---|---|---|
debug |
debug |
Breadcrumb only |
info |
info |
Breadcrumb only |
success |
info |
Breadcrumb only |
warning |
warning |
Breadcrumb + Event (issue) |
error |
error |
Breadcrumb + Event (issue) |
critical |
fatal |
Breadcrumb + Event (fatal issue) |
All logs that pass the filter are added as breadcrumbs. warning, error, and critical additionally create events (issues) in Sentry. Logs with exceptions use captureException instead of captureMessage.
Configuration Options
SentryLoggerProvider Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
dsn |
String |
required | Your Sentry project DSN |
filter |
LogFilter |
MinLevelFilter(FlexLogLevel.error) |
Filter to determine which logs to send |
optionsConfiguration |
void Function(SentryFlutterOptions)? |
null |
Callback to configure all Sentry options |
Available Filters
| Filter | Description | Example |
|---|---|---|
MinLevelFilter |
Filter by minimum log level | MinLevelFilter(FlexLogLevel.warning) |
TypeFilter |
Filter specific log type | TypeFilter<ErrorLog>() |
DevelopmentOnlyFilter |
Only log in development mode | DevelopmentOnlyFilter() |
CompositeLogFilter |
Combine multiple filters | CompositeLogFilter.and([...]) |
For all available Sentry options see SentryFlutterOptions.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Libraries
- flex_logger_sentry
- Sentry integration for FlexLogger.