flutter_awesome_logger 0.1.7
flutter_awesome_logger: ^0.1.7 copied to clipboard
Awesome debugging with floating logger, automatic API logging (using interceptor), and a beautiful UI for viewing logs.
Flutter Awesome Logger π #
A comprehensive Flutter logging package that makes debugging a breeze! Features a floating logger, automatic API logging with Dio interceptor, and a beautiful UI for viewing logs.
β¨ Features #
- π± Floating Logger Button - Always accessible debug button that floats over your app (can be disabled)
- π Automatic API Logging - Built-in Dio interceptor for seamless API request/response logging
- π¨ Beautiful UI - Clean, modern interface for viewing logs with syntax highlighting
- π Multiple Log Levels - Support for debug, info, warning, error, and verbose logs
- πΎ Smart Storage - Logs are stored only when logger is enabled, conserving memory
- βΈοΈ Pause/Resume Logging - Temporarily pause all logging with visual indicators
- π Search & Filter - Easily find specific logs with search and filtering capabilities
- π― Simple Configuration - Single
enabledproperty controls both UI and storage - π± Responsive Design - Works perfectly on all screen sizes
πΈ Screenshots #
|
Floating Logger Button |
API Logs View |
|
General Logs View |
Log Details |
π Getting Started #
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_awesome_logger: ^0.1.0
Then run:
flutter pub get
Basic Usage #
Option 1: Auto-Configuration (Recommended - Easiest)
Simply wrap your app with FlutterAwesomeLogger and pass the configuration:
import 'package:flutter/material.dart';
import 'package:flutter_awesome_logger/flutter_awesome_logger.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
// Example: Enable logger after checking some condition
Future<bool> _shouldEnableLogger() async {
// Check if we're in debug mode, user preferences, etc.
await Future.delayed(const Duration(seconds: 2)); // Simulate async check
return true; // Or false based on your logic
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FlutterAwesomeLogger(
enabled: _shouldEnableLogger(), // Can be Future<bool> or bool
// Auto-configure logger settings
loggerConfig: const AwesomeLoggerConfig(
maxLogEntries: 500,
showFilePaths: true,
showEmojis: true,
useColors: true,
),
// Floating logger UI configuration
config: const FloatingLoggerConfig(
backgroundColor: Colors.deepPurple,
icon: Icons.developer_mode,
showCount: true,
enableGestures: true,
autoSnapToEdges: true,
),
child: const YourHomePage(),
),
);
}
}
Option 2: Manual Configuration (Advanced)
For more control, configure manually in main(). Note: Manual configuration doesn't automatically control log storage - use Option 1 for simpler setup.
import 'package:flutter/material.dart';
import 'package:flutter_awesome_logger/flutter_awesome_logger.dart';
void main() {
// Manual configuration
LoggingUsingLogger.configure(
const AwesomeLoggerConfig(
maxLogEntries: 500,
showFilePaths: true,
showEmojis: true,
useColors: true,
),
);
// Manual initialization
FloatingLoggerManager.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FlutterAwesomeLogger(
enabled: true, // Controls both floating logger AND log storage
// Don't auto-configure since we did it manually
config: const FloatingLoggerConfig(
backgroundColor: Colors.deepPurple,
icon: Icons.developer_mode,
showCount: true,
enableGestures: true,
autoSnapToEdges: true,
),
child: const YourHomePage(),
),
);
}
}
- Start logging:
import 'package:flutter_awesome_logger/flutter_awesome_logger.dart';
// Use the global logger instance
logger.d('Debug message');
logger.i('Info message');
logger.w('Warning message');
logger.e('Error message');
logger.v('Verbose message');
API Logging with Dio #
Automatically log all your API requests and responses:
import 'package:dio/dio.dart';
import 'package:flutter_awesome_logger/flutter_awesome_logger.dart';
final dio = Dio();
// Add the awesome logger interceptor
dio.interceptors.add(AwesomeLoggerDioInterceptor());
// Now all your API calls will be automatically logged!
final response = await dio.get('https://api.example.com/data');
π§ Configuration Options #
FlutterAwesomeLogger #
The enabled parameter can accept either a bool or Future<bool>:
enabled: true- Logger is immediately enabledenabled: false- Logger is immediately disabledenabled: someFuture()- Logger waits for the Future to resolve, then enables/disables accordingly
This allows for conditional logger initialization based on async operations like checking debug mode, user preferences, or remote configuration.
AwesomeLoggerConfig #
const AwesomeLoggerConfig({
int maxLogEntries = 1000, // Maximum number of log entries to keep
bool showFilePaths = true, // Show file paths in console output
bool showEmojis = true, // Show emojis in console output
bool useColors = true, // Use colors in console output
int stackTraceLines = 0, // Number of stack trace lines to show
});
FloatingLoggerConfig #
const FloatingLoggerConfig({
Color backgroundColor = Colors.blue, // Background color of the floating button
IconData icon = Icons.bug_report, // Icon for the floating button
bool showCount = true, // Show log count badge
bool enableGestures = true, // Enable drag gestures
bool autoSnapToEdges = true, // Auto-snap to screen edges
double size = 56.0, // Size of the floating button
});
π Advanced Usage #
Custom Log Formatting #
// Log with custom formatting
logger.logCustom(
level: LogLevel.info,
message: 'Custom formatted message',
error: someError,
stackTrace: someStackTrace,
);
Accessing Log History #
// Get all stored logs
final logs = FlutterAwesomeLogger.getLogs();
// Get logs by level
final errorLogs = FlutterAwesomeLogger.getLogsByLevel(LogLevel.error);
// Clear all logs
FlutterAwesomeLogger.clearLogs();
Programmatically Show Logger UI #
// Show the logger history page
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoggerHistoryPage(),
),
);
Pause/Resume Logging #
// Pause all logging (both console and storage)
LoggingUsingLogger.setPauseLogging(true);
// Resume logging
LoggingUsingLogger.setPauseLogging(false);
// Check if logging is paused
bool isPaused = LoggingUsingLogger.isPaused;
π¨ Customization #
The logger UI is highly customizable. You can:
- Change colors and themes
- Customize the floating button appearance
- Configure log display formats
- Add custom filters and search options
- Pause/resume logging as needed
- Control logging behavior with simple configuration
π€ Contributing #
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π Issues #
If you encounter any issues or have feature requests, please file them in the issue tracker.
π Support #
- π§ Email: [email protected]
- π¦ Twitter: @codeastartup01dev
- π¬ Discord: Join our community
Made with β€οΈ by codeastartup01dev