Abrova
☰ Docs menu · Flutter SDK logging

Flutter SDK Logging

Battery-efficient logging for Flutter apps with automatic batching, exponential backoff, and mobile lifecycle awareness.

Last updated: 27 Oct 2026

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 vs. messages.

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.

Automatic Batching

Logs are buffered and sent in batches (default: 50)

Exponential Backoff

Retries failed batches with increasing delays (2s, 4s, 8s... up to 60s, max 10 retries)

Lifecycle Hooks

Auto-flushes on app background, pauses when inactive

Max Buffer Size

Drops oldest logs when buffer exceeds 1000 to prevent memory issues

Lazy Timer

Timer only runs when buffer has logs — no battery drain when idle

User Context

Automatically attaches user ID set via AbrovaTrace.setUserId()

Enable Logging#

After initializing AbrovaTrace, enable the logging service:

dart
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

dart
// 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

dart
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#

dart
// Force flush all buffered logs
await AbrovaTrace.flushLogs();

// Check buffer status
print('Pending logs: ${AbrovaTrace.pendingLogCount}');

Configuration#

OptionTypeRequiredDescription
sourceIdString?NoIdentifier 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
sourceNameString?NoHuman-readable name for this source
batchSizeintNoFlush when buffer reaches this size (default: 50)
flushIntervalDurationNoMax 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 Early

Enable logging right after AbrovaTrace.init() to capture all events

Use Source IDs

Set a meaningful sourceId to identify logs from this app in the dashboard

Add Metadata

Include structured metadata (user ID, screen name, etc.) for easier debugging

Use Appropriate Levels

Use info for normal events, warn for potential issues, error for failures

Flush on Shutdown

Call AbrovaTrace.flushLogs() before app close to ensure all logs are sent

Don't Over-Log

Avoid logging in tight loops — the buffer has a max size and will drop oldest logs

Was this page helpful?
Report a problem