refactor: debug logs
This commit is contained in:
73
lib/core/utils/debug_logger.dart
Normal file
73
lib/core/utils/debug_logger.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Centralized debug logging utility for the entire app
|
||||
class DebugLogger {
|
||||
static const bool _enabled = kDebugMode;
|
||||
|
||||
/// Log debug information
|
||||
static void log(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('🔍 $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log errors
|
||||
static void error(String message, [Object? error]) {
|
||||
if (_enabled) {
|
||||
if (error != null) {
|
||||
debugPrint('❌ $message: $error');
|
||||
} else {
|
||||
debugPrint('❌ $message');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Log warnings
|
||||
static void warning(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('⚠️ $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log success/info messages
|
||||
static void info(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('ℹ️ $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log navigation events
|
||||
static void navigation(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('🧭 $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log authentication events
|
||||
static void auth(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('🔐 $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log streaming events
|
||||
static void stream(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('📡 $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log validation events
|
||||
static void validation(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('✅ $message');
|
||||
}
|
||||
}
|
||||
|
||||
/// Log storage events
|
||||
static void storage(String message) {
|
||||
if (_enabled) {
|
||||
debugPrint('💾 $message');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'debug_logger.dart';
|
||||
|
||||
/// Utility class for parsing and extracting reasoning/thinking content from messages
|
||||
class ReasoningParser {
|
||||
@@ -7,21 +8,21 @@ class ReasoningParser {
|
||||
if (content.isEmpty) return null;
|
||||
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'DEBUG: Parsing content: ${content.substring(0, content.length > 200 ? 200 : content.length)}...',
|
||||
DebugLogger.log(
|
||||
'Parsing content: ${content.substring(0, content.length > 200 ? 200 : content.length)}...',
|
||||
);
|
||||
}
|
||||
|
||||
// Check if content contains reasoning
|
||||
if (!content.contains('<details type="reasoning"')) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('DEBUG: No reasoning content found in text');
|
||||
DebugLogger.log('No reasoning content found in text');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (kDebugMode) {
|
||||
debugPrint('DEBUG: Found reasoning tags in content');
|
||||
DebugLogger.log('Found reasoning tags in content');
|
||||
}
|
||||
|
||||
// Match the <details> tag with type="reasoning"
|
||||
@@ -45,18 +46,18 @@ class ReasoningParser {
|
||||
final flexMatch = flexRegex.firstMatch(content);
|
||||
if (flexMatch != null) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('DEBUG: Found flexible match: ${flexMatch.group(0)}');
|
||||
DebugLogger.log('Found flexible match: ${flexMatch.group(0)}');
|
||||
}
|
||||
} else {
|
||||
if (kDebugMode) {
|
||||
debugPrint('DEBUG: No flexible match found either');
|
||||
DebugLogger.log('No flexible match found either');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (kDebugMode) {
|
||||
debugPrint('DEBUG: Regex matched successfully');
|
||||
DebugLogger.log('Regex matched successfully');
|
||||
}
|
||||
|
||||
final isDone = match.group(1) == 'true';
|
||||
@@ -65,10 +66,10 @@ class ReasoningParser {
|
||||
final reasoning = match.group(4)?.trim() ?? '';
|
||||
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'DEBUG: Parsed values - isDone: $isDone, duration: $duration, summary: $summary',
|
||||
DebugLogger.log(
|
||||
'Parsed values - isDone: $isDone, duration: $duration, summary: $summary',
|
||||
);
|
||||
debugPrint('DEBUG: Reasoning content length: ${reasoning.length}');
|
||||
DebugLogger.log('Reasoning content length: ${reasoning.length}');
|
||||
}
|
||||
|
||||
// Remove the reasoning section from the main content
|
||||
|
||||
Reference in New Issue
Block a user