Question #110EasyDart Basics

What is Flutter logging view ?

#flutter#dart

Answer

Overview

Flutter Logging View (called Logging in Flutter DevTools) is a tool that displays log messages from your Flutter app in a structured, filterable interface — much better than reading a raw terminal output.


Accessing the Logging View

bash
# Run app in debug mode
flutter run

# Open DevTools (press 'd' in terminal or click in IDE)
# In DevTools browser: go to "Logging" tab

Using Logging in Code

Simple print (visible in Logging View)

dart
print('App started');           // Shows in logging view
debugPrint('Debug message');    // Throttled print — better for rapid logs

Developer Log (Best for production logging)

dart
import 'dart:developer';

log('User logged in', name: 'Auth');           // With category
log('API call', name: 'Network', level: 800);  // With level
log('Error!', name: 'Error', error: exception, stackTrace: stack);

Logging Package (Structured)

yaml
dependencies:
  logging: ^1.2.0
dart
import 'package:logging/logging.dart';

final _logger = Logger('MyWidget');

void setup() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    debugPrint('[${record.level.name}] ${record.loggerName}: ${record.message}');
  });
}

// Usage
_logger.info('Data loaded successfully');
_logger.warning('Slow response: ${duration}ms');
_logger.severe('API failed!', error, stackTrace);

DevTools Logging View Features

FeatureDescription
Filter by textSearch specific log messages
Filter by levelShow only errors/warnings
TimestampsWhen each log occurred
Stack tracesClick errors to see stack trace
Clear logsClear all visible logs
Copy messagesCopy log text

Log Levels

dart
// dart:developer levels
Level.FINEST  // 300 — most verbose
Level.FINER   // 400
Level.FINE    // 500
Level.CONFIG  // 700
Level.INFO    // 800 — general info
Level.WARNING // 900 — potential issues
Level.SEVERE  // 1000 — errors
Level.SHOUT   // 1200 — critical

Best Practice: Use

text
dart:developer
's
text
log()
function instead of
text
print()
in production code. It shows in the DevTools Logging view with proper categorization and doesn't get truncated like
text
print()
.