Files
geo/app/lib/core/services/logger_service.dart
Pierre 206c76c7db feat: Livraison version 3.0.6
- Amélioration de la gestion des entités et des utilisateurs
- Mise à jour des modèles Amicale et Client avec champs supplémentaires
- Ajout du service de logging et amélioration du chargement UI
- Refactoring des formulaires utilisateur et amicale
- Intégration de file_picker et image_picker pour la gestion des fichiers
- Amélioration de la gestion des membres et de leur suppression
- Optimisation des performances de l'API
- Mise à jour de la documentation technique

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-08 20:33:54 +02:00

163 lines
4.4 KiB
Dart
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/foundation.dart';
import 'package:geosector_app/core/services/api_service.dart';
/// Service de logging centralisé qui désactive automatiquement les logs en production
class LoggerService {
static LoggerService? _instance;
static bool? _isProduction;
// Singleton
static LoggerService get instance {
_instance ??= LoggerService._internal();
return _instance!;
}
LoggerService._internal();
/// Détermine si on est en production
static bool get isProduction {
if (_isProduction != null) return _isProduction!;
try {
// Vérifier si ApiService est initialisé
final env = ApiService.instance.getCurrentEnvironment();
_isProduction = env == 'PROD';
} catch (e) {
// Si ApiService n'est pas encore initialisé, utiliser kReleaseMode
_isProduction = kReleaseMode;
}
return _isProduction!;
}
/// Réinitialiser le cache de l'environnement (utile pour les tests)
static void resetEnvironmentCache() {
_isProduction = null;
}
/// Log simple (remplace debugPrint)
static void log(String message, {String? prefix}) {
if (!isProduction) {
if (prefix != null) {
debugPrint('$prefix $message');
} else {
debugPrint(message);
}
}
}
/// Log d'information
static void info(String message) {
if (!isProduction) {
debugPrint(' $message');
}
}
/// Log de succès
static void success(String message) {
if (!isProduction) {
debugPrint('$message');
}
}
/// Log d'avertissement
static void warning(String message) {
if (!isProduction) {
debugPrint('⚠️ $message');
}
}
/// Log d'erreur (toujours affiché même en production pour le debugging)
static void error(String message, [dynamic error, StackTrace? stackTrace]) {
// Les erreurs sont toujours loggées, même en production
debugPrint('$message');
if (error != null) {
debugPrint(' Error: $error');
}
if (stackTrace != null && !isProduction) {
// La stack trace n'est affichée qu'en DEV/REC
debugPrint(' Stack trace:\n$stackTrace');
}
}
/// Log de debug (avec emoji personnalisé)
static void debug(String message, {String emoji = '🔧'}) {
if (!isProduction) {
debugPrint('$emoji $message');
}
}
/// Log de requête API
static void api(String message) {
if (!isProduction) {
debugPrint('🔗 $message');
}
}
/// Log de base de données
static void database(String message) {
if (!isProduction) {
debugPrint('💾 $message');
}
}
/// Log de navigation
static void navigation(String message) {
if (!isProduction) {
debugPrint('🧭 $message');
}
}
/// Log de performance/timing
static void performance(String message) {
if (!isProduction) {
debugPrint('⏱️ $message');
}
}
/// Log conditionnel basé sur un flag custom
static void conditional(String message, {required bool condition}) {
if (!isProduction && condition) {
debugPrint(message);
}
}
/// Groupe de logs (pour regrouper visuellement des logs liés)
static void group(String title, List<String> messages) {
if (!isProduction) {
debugPrint('┌─ $title');
for (int i = 0; i < messages.length; i++) {
if (i == messages.length - 1) {
debugPrint('└─ ${messages[i]}');
} else {
debugPrint('├─ ${messages[i]}');
}
}
}
}
/// Log d'objet JSON (formaté)
static void json(String label, Map<String, dynamic> data) {
if (!isProduction) {
debugPrint('📋 $label:');
data.forEach((key, value) {
debugPrint(' $key: $value');
});
}
}
}
/// Extension pour faciliter l'utilisation
extension LoggerExtension on String {
void log({String? prefix}) => LoggerService.log(this, prefix: prefix);
void logInfo() => LoggerService.info(this);
void logSuccess() => LoggerService.success(this);
void logWarning() => LoggerService.warning(this);
void logError([dynamic error, StackTrace? stackTrace]) =>
LoggerService.error(this, error, stackTrace);
void logDebug({String emoji = '🔧'}) => LoggerService.debug(this, emoji: emoji);
void logApi() => LoggerService.api(this);
void logDatabase() => LoggerService.database(this);
void logNavigation() => LoggerService.navigation(this);
void logPerformance() => LoggerService.performance(this);
}