strategic_logger 1.0.0
strategic_logger: ^1.0.0 copied to clipboard
Modern, high-performance logging framework for Flutter & Dart applications with multi-strategy logging, isolate-based processing, and beautiful console output.
Strategic Logger π #
Modern, high-performance logging framework for Flutter & Dart applications
Strategic Logger is a cutting-edge logging solution that combines multi-strategy logging, isolate-based processing, and beautiful console output to provide developers with the most powerful and flexible logging experience.
β¨ Why Strategic Logger? #
π― One Call, All Strategies #
Log once and send to multiple destinations simultaneously - Console, Firebase, Sentry, Datadog, New Relic, and more.
β‘ Performance First #
- Isolate-based processing - Never block the main thread
- Async queue with backpressure - Handle high log volumes efficiently
- Automatic batching - Reduce network overhead
- Performance monitoring - Built-in metrics and insights
π¨ Beautiful Console Output #
- Modern formatting with colors, emojis, and structured layout
- Rich context display with metadata and stack traces
- Timestamp precision with millisecond accuracy
π Drop-in Replacement #
100% compatible with popular logger packages - no code changes required!
π Quick Start #
Installation #
Add Strategic Logger to your pubspec.yaml
:
dependencies:
strategic_logger: ^0.2.0
Then run:
flutter pub get
Basic Usage #
import 'package:strategic_logger/strategic_logger.dart';
void main() async {
// Initialize once at app startup
await logger.initialize(
level: LogLevel.debug,
strategies: [
ConsoleLogStrategy(
useModernFormatting: true,
useColors: true,
useEmojis: true,
),
FirebaseAnalyticsLogStrategy(),
FirebaseCrashlyticsLogStrategy(),
],
useIsolates: true,
enablePerformanceMonitoring: true,
);
// Start logging!
await logger.info('App started successfully');
await logger.error('Something went wrong', stackTrace: StackTrace.current);
}
π― Features #
π§ Core Features #
- Multiple Log Strategies - Console, Firebase, Sentry, Datadog, New Relic
- Custom Strategies - Extend with your own logging destinations
- Log Levels - Debug, Info, Warning, Error, Fatal
- Structured Logging - Rich metadata and context support
- Error Handling - Robust error management with predefined types
π Modern Features #
- Isolate Processing - Heavy operations run in background isolates
- Performance Monitoring - Built-in metrics and performance tracking
- Modern Console - Beautiful, colorful, emoji-rich output
- Compatibility Layer - Drop-in replacement for popular logger packages
- Async Queue - Efficient log processing with backpressure control
- Batch Processing - Automatic batching for network strategies
- Retry Logic - Exponential backoff for failed operations
π Usage Examples #
Async Logging (Recommended) #
// Basic logging
await logger.debug('Debug message');
await logger.info('Info message');
await logger.warning('Warning message');
await logger.error('Error message');
await logger.fatal('Fatal error');
// Structured logging with context
await logger.info('User action', context: {
'userId': '123',
'action': 'login',
'timestamp': DateTime.now().toIso8601String(),
});
// Log with events
await logger.log('User logged in', event: LogEvent(
eventName: 'user_login',
eventMessage: 'User successfully logged in',
parameters: {'userId': '123'},
));
Sync Logging (Compatibility) #
// Drop-in replacement for popular logger packages
logger.debugSync('Debug message');
logger.infoSync('Info message');
logger.errorSync('Error message');
// Or use the compatibility extension
loggerCompatibility.debug('Debug message');
loggerCompatibility.info('Info message');
loggerCompatibility.error('Error message');
Performance Monitoring #
// Get performance statistics
final stats = logger.getPerformanceStats();
print('Performance Stats: $stats');
// Force flush all queued logs
await logger.flush();
π¨ Modern Console Output #
Experience beautiful, structured console output:
π 14:30:25.123 DEBUG User action completed
π Event: USER_ACTION
Message: User completed purchase
Parameters:
userId: 123
amount: 99.99
π Context:
timestamp: 2024-01-15T14:30:25.123Z
source: mobile_app
π§ Configuration #
Advanced Initialization #
await logger.initialize(
level: LogLevel.info,
strategies: [
// Console with modern formatting
ConsoleLogStrategy(
useModernFormatting: true,
useColors: true,
useEmojis: true,
showTimestamp: true,
showContext: true,
),
// Firebase Analytics
FirebaseAnalyticsLogStrategy(),
// Firebase Crashlytics
FirebaseCrashlyticsLogStrategy(),
// Datadog
DatadogLogStrategy(
apiKey: 'your-datadog-api-key',
service: 'my-app',
env: 'production',
tags: 'team:mobile,version:1.0.0',
),
// New Relic
NewRelicLogStrategy(
licenseKey: 'your-newrelic-license-key',
appName: 'my-app',
environment: 'production',
),
],
// Modern features
useIsolates: true,
enablePerformanceMonitoring: true,
enableModernConsole: true,
);
Custom Strategies #
Create your own logging strategy:
class MyCustomLogStrategy extends LogStrategy {
@override
Future<void> log({dynamic message, LogEvent? event}) async {
// Use isolates for heavy processing
final result = await isolateManager.executeInIsolate(
'customTask',
{'message': message, 'event': event?.toMap()},
);
// Send to your custom service
await _sendToCustomService(result);
}
@override
Future<void> info({dynamic message, LogEvent? event}) async {
await log(message: message, event: event);
}
@override
Future<void> error({dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
await log(message: error, event: event);
}
@override
Future<void> fatal({dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
await log(message: error, event: event);
}
}
π Performance #
Strategic Logger is designed for high performance:
- Isolate-based processing prevents blocking the main thread
- Automatic batching reduces network overhead
- Async queue with backpressure handles high log volumes
- Performance monitoring tracks operation metrics
- Efficient serialization minimizes memory usage
Performance Metrics #
final stats = logger.getPerformanceStats();
print('Total operations: ${stats['processLogEntry']?.totalOperations}');
print('Average duration: ${stats['processLogEntry']?.averageDuration}ms');
print('Error rate: ${stats['processLogEntry']?.errorRate}%');
π Migration Guide #
From v0.1.x to v0.2.x #
The new version introduces breaking changes for better performance and modern features:
// Old way (v0.1.x)
logger.initialize(
level: LogLevel.info,
strategies: [ConsoleLogStrategy()],
);
// New way (v0.2.x)
await logger.initialize(
level: LogLevel.info,
strategies: [
ConsoleLogStrategy(
useModernFormatting: true,
useColors: true,
useEmojis: true,
),
],
useIsolates: true,
enablePerformanceMonitoring: true,
enableModernConsole: true,
);
π Supported Platforms #
- β Flutter (iOS, Android, Web, Desktop)
- β Dart CLI applications
- β Dart VM applications
- β Flutter Web
- β Flutter Desktop (Windows, macOS, Linux)
πΊοΈ Roadmap #
- β Elasticsearch strategy
- β Splunk strategy
- β CloudWatch strategy
- β File-based logging strategy
- β SQLite logging strategy
- β WebSocket logging strategy
- β Compression support
- β Encryption support
π€ Contributing #
We welcome contributions! Please see our Contributing Guide for details.
Development Setup #
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
π Support #
If you find Strategic Logger helpful, please consider:
- β Starring the repository
- π Reporting bugs
- π‘ Suggesting new features
- π€ Contributing code
- β Buy me a coffee
π’ Sponsored by #
Hypn Tech - Maintainer & Sponsor
Building the future of mobile applications with cutting-edge technology
π License #
Strategic Logger is released under the MIT License. See LICENSE for details.
π Documentation #
- API Documentation
- Examples
- Changelog
- Contributing Guide