Appearance
📊 Logging & Monitoring Standards for Flutter
Core Standards
Logging Requirements
- Always use centralized logging with AppLogger class
- Enable logging only in debug mode to avoid performance impact
- Use appropriate log levels (info, warning, error, success)
- Include contextual information in log messages
- Avoid logging sensitive data (passwords, tokens, personal info) in production code
Logging Levels Rules
- INFO - General information about application flow
- WARNING - Warning conditions that should be investigated
- ERROR - Critical errors that need immediate attention
- SUCCESS - Successful operations and positive outcomes
- CUSTOM - Specialized logging with custom tags and colors
Flags for logging
We use a flags class to enable or disable logging for different levels.
dart
// lib/shared/utils/flags.dart
class Flags {
static bool get isLoggerEnabled => true;
static bool get isLoggerInfoEnabled => true;
static bool get isLoggerWarningEnabled => true;
static bool get isLoggerErrorEnabled => true;
static bool get isLoggerSuccessEnabled => true;
static bool get isLoggerCustomEnabled => true;
}Monitoring Setup
Flutter DevTools Integration
- Enable DevTools for performance monitoring
- Use Inspector for widget tree analysis
- Monitor Memory usage and leaks
- Track Performance metrics and frame rates
- Debug Network requests and responses
Performance Monitoring Rules
- Monitor frame rendering performance
- Track memory usage and potential leaks
- Measure app startup time
- Monitor network performance and latency
- Track user interactions and response times
DevTools Integration
DevTools Features Usage
- Inspector Tab - Widget tree analysis and debugging
- Performance Tab - Frame rendering and performance analysis
- Memory Tab - Memory usage and leak detection
- Network Tab - HTTP requests and responses monitoring
- Logging Tab - Real-time log viewing and filtering
Performance Monitoring with DevTools
- Frame Analysis - Monitor frame rendering performance
- Memory Profiling - Track memory usage and leaks
- Network Monitoring - Analyze API calls and responses
- Timeline Analysis - Track app performance over time
- CPU Profiling - Monitor CPU usage and bottlenecks
Performance Monitoring
Memory Monitoring Rules
- Monitor memory usage regularly
- Detect memory leaks early
- Use DevTools Memory tab for analysis
- Log memory snapshots at key points
- Monitor object allocation patterns
Network Monitoring Rules
- Log all API requests and responses
- Monitor response times and timeouts
- Track error rates and types
- Use DevTools Network tab for analysis
- Monitor data usage and bandwidth
Common Violations
❌ DO NOT Violate These Rules
- Don't use
print()statements - Use AppLogger instead - Don't log in production - Only log in debug mode
- Don't ignore log levels - Use appropriate levels for messages
- Don't log without context - Include relevant identifiers
- Don't log excessive data - Keep logs concise and meaningful
- Don't ignore DevTools - Use DevTools for monitoring
- Don't skip memory monitoring - Monitor for leaks
- Don't ignore network monitoring - Track API performance
- Don't ignore error logging - Always log errors with context
✅ ALWAYS Follow These Rules
- Use AppLogger for all logging needs
- Enable logging only in debug mode with kDebugMode
- Use appropriate log levels (info, warning, error, success)
- Include contextual information in log messages
- Use custom logging for specialized needs
- Enable DevTools for performance monitoring
- Monitor memory usage and detect leaks
- Track network performance and errors
- Use structured logging with consistent formats
- Include timing information for performance monitoring
- Log state changes and important transitions
- Use colored output for better readability
- Monitor frame performance with DevTools
- Track user interactions and response times
- Use configurable log levels for different environments
- Log API requests and responses for debugging
- Monitor app startup and initialization time
- Use DevTools Inspector for widget debugging
- Track error rates and types for monitoring
- Implement performance monitoring utilities