Flutter SDK Logging
Battery-efficient logging for Flutter apps with automatic batching, exponential backoff, and mobile lifecycle awareness.
Battery-efficient logging for Flutter apps with automatic batching, exponential backoff, and mobile lifecycle awareness. Logs are buffered and sent in batches to minimize network usage.
Logs (AbrovaTrace.info(), warn(), logError(), ...) are buffered, batched and shown under Abrova Trace → Logs. They are separate from AbrovaTrace.captureMessage(), which sends one event right away to Abrova Trace → Messages. Neither creates an issue — use captureException() for that.
Logs are buffered and sent in batches (default: 50)
Retries failed batches with increasing delays (2s, 4s, 8s... up to 60s, max 10 retries)
Auto-flushes on app background, pauses when inactive
Drops oldest logs when buffer exceeds 1000 to prevent memory issues
Timer only runs when buffer has logs — no battery drain when idle
Automatically attaches user ID set via AbrovaTrace.setUserId()
Enable Logging#
After initializing AbrovaTrace, enable the logging service:
import 'package:abrova_trace_flutter_sdk/abrova_trace_flutter_sdk.dart'; // Initialize AbrovaTrace first await AbrovaTrace.init(AbrovaTraceConfig( apiKey: 'ab_live_your_api_key', environment: 'production', release: '1.0.0', )); // Enable logging with a source identifier AbrovaTrace.enableLogging( sourceId: 'my-flutter-app', sourceName: 'My Flutter App', batchSize: 50, flushInterval: Duration(seconds: 5), );
If you call a log method before enableLogging(), logging is enabled automatically with the defaults and no sourceId. Logging needs the Flutter binding, so enable it (or send the first log) after WidgetsFlutterBinding.ensureInitialized().
Sending Logs#
Convenience Methods
// Info log
AbrovaTrace.info('User login successful', metadata: {
'user_id': 'user_123',
});
// Warning log
AbrovaTrace.warn('Slow API response', metadata: {
'endpoint': '/api/users',
'duration_ms': 2500,
});
// Error log
AbrovaTrace.logError('Database query failed', metadata: {
'query': 'SELECT * FROM users',
'error': 'Connection timeout',
});
// Debug log
AbrovaTrace.debug('Cache hit for key: user_123');
// Trace log
AbrovaTrace.trace('Entering function processPayment()');
// Fatal log
AbrovaTrace.fatal('App crashed unexpectedly', metadata: {
'last_screen': 'checkout',
});Generic Log Method
import 'package:abrova_trace_flutter_sdk/abrova_trace_flutter_sdk.dart';
// Generic log with explicit level
AbrovaTrace.log(
'Custom event',
level: LogLevel.info,
metadata: {'key': 'value'},
);Log Levels#
- trace —
AbrovaTrace.trace()— Very detailed trace-level debugging - debug —
AbrovaTrace.debug()— Debug information during development - info —
AbrovaTrace.info()— General application information - warn —
AbrovaTrace.warn()— Warnings about potential issues - error —
AbrovaTrace.logError()— Errors that need attention - fatal —
AbrovaTrace.fatal()— Critical/unrecoverable errors
Mobile Lifecycle Behavior#
The logging service automatically handles app lifecycle events:
- App Paused/Background — Immediately flushes all buffered logs
- App Resumed — Resets retry counter and resumes normal operation
- App Detached — Flushes and stops sending
- Buffer Overflow — Drops oldest logs when exceeding max buffer (1000)
Manual Operations#
// Force flush all buffered logs
await AbrovaTrace.flushLogs();
// Check buffer status
print('Pending logs: ${AbrovaTrace.pendingLogCount}');Configuration#
| Option | Type | Required | Description |
|---|---|---|---|
| sourceId | String? | No | Identifier for this log source (e.g., "my-flutter-app"). Required for batch sending — without it each log is sent in its own request and failed sends are not retried |
| sourceName | String? | No | Human-readable name for this source |
| batchSize | int | No | Flush when buffer reaches this size (default: 50) |
| flushInterval | Duration | No | Max time before flush (default: 5 seconds) |
The buffer holds at most 1000 logs (oldest are dropped first). This limit is fixed and cannot be changed through enableLogging().
Best Practices#
Enable logging right after AbrovaTrace.init() to capture all events
Set a meaningful sourceId to identify logs from this app in the dashboard
Include structured metadata (user ID, screen name, etc.) for easier debugging
Use info for normal events, warn for potential issues, error for failures
Call AbrovaTrace.flushLogs() before app close to ensure all logs are sent
Avoid logging in tight loops — the buffer has a max size and will drop oldest logs