Skip to content

📊 Logging & Monitoring Standards for Flutter

Core Standards

Logging Requirements

  1. Always use centralized logging with AppLogger class
  2. Enable logging only in debug mode to avoid performance impact
  3. Use appropriate log levels (info, warning, error, success)
  4. Include contextual information in log messages
  5. Avoid logging sensitive data (passwords, tokens, personal info) in production code

Logging Levels Rules

  1. INFO - General information about application flow
  2. WARNING - Warning conditions that should be investigated
  3. ERROR - Critical errors that need immediate attention
  4. SUCCESS - Successful operations and positive outcomes
  5. 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

  1. Enable DevTools for performance monitoring
  2. Use Inspector for widget tree analysis
  3. Monitor Memory usage and leaks
  4. Track Performance metrics and frame rates
  5. Debug Network requests and responses

Performance Monitoring Rules

  1. Monitor frame rendering performance
  2. Track memory usage and potential leaks
  3. Measure app startup time
  4. Monitor network performance and latency
  5. Track user interactions and response times

DevTools Integration

DevTools Features Usage

  1. Inspector Tab - Widget tree analysis and debugging
  2. Performance Tab - Frame rendering and performance analysis
  3. Memory Tab - Memory usage and leak detection
  4. Network Tab - HTTP requests and responses monitoring
  5. Logging Tab - Real-time log viewing and filtering

Performance Monitoring with DevTools

  1. Frame Analysis - Monitor frame rendering performance
  2. Memory Profiling - Track memory usage and leaks
  3. Network Monitoring - Analyze API calls and responses
  4. Timeline Analysis - Track app performance over time
  5. CPU Profiling - Monitor CPU usage and bottlenecks

Performance Monitoring

Memory Monitoring Rules

  1. Monitor memory usage regularly
  2. Detect memory leaks early
  3. Use DevTools Memory tab for analysis
  4. Log memory snapshots at key points
  5. Monitor object allocation patterns

Network Monitoring Rules

  1. Log all API requests and responses
  2. Monitor response times and timeouts
  3. Track error rates and types
  4. Use DevTools Network tab for analysis
  5. Monitor data usage and bandwidth

Common Violations

DO NOT Violate These Rules

  1. Don't use print() statements - Use AppLogger instead
  2. Don't log in production - Only log in debug mode
  3. Don't ignore log levels - Use appropriate levels for messages
  4. Don't log without context - Include relevant identifiers
  5. Don't log excessive data - Keep logs concise and meaningful
  6. Don't ignore DevTools - Use DevTools for monitoring
  7. Don't skip memory monitoring - Monitor for leaks
  8. Don't ignore network monitoring - Track API performance
  9. Don't ignore error logging - Always log errors with context

ALWAYS Follow These Rules

  1. Use AppLogger for all logging needs
  2. Enable logging only in debug mode with kDebugMode
  3. Use appropriate log levels (info, warning, error, success)
  4. Include contextual information in log messages
  5. Use custom logging for specialized needs
  6. Enable DevTools for performance monitoring
  7. Monitor memory usage and detect leaks
  8. Track network performance and errors
  9. Use structured logging with consistent formats
  10. Include timing information for performance monitoring
  11. Log state changes and important transitions
  12. Use colored output for better readability
  13. Monitor frame performance with DevTools
  14. Track user interactions and response times
  15. Use configurable log levels for different environments
  16. Log API requests and responses for debugging
  17. Monitor app startup and initialization time
  18. Use DevTools Inspector for widget debugging
  19. Track error rates and types for monitoring
  20. Implement performance monitoring utilities