Merge pull request #214 from cogwheel0/refactor-remove-verbose-logging
refactor(logging): Remove verbose debug logging across multiple services
This commit is contained in:
@@ -85,10 +85,6 @@ class ApiAuthInterceptor extends Interceptor {
|
|||||||
final requiresAuth = _requiresAuth(path);
|
final requiresAuth = _requiresAuth(path);
|
||||||
final hasOptionalAuth = _hasOptionalAuth(path);
|
final hasOptionalAuth = _hasOptionalAuth(path);
|
||||||
|
|
||||||
DebugLogger.auth(
|
|
||||||
'Auth interceptor for $path - requires: $requiresAuth, optional: $hasOptionalAuth, token present: ${_authToken != null}',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (requiresAuth) {
|
if (requiresAuth) {
|
||||||
// Strictly required authentication
|
// Strictly required authentication
|
||||||
if (_authToken == null || _authToken!.isEmpty) {
|
if (_authToken == null || _authToken!.isEmpty) {
|
||||||
|
|||||||
@@ -675,7 +675,6 @@ class Models extends _$Models {
|
|||||||
});
|
});
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
DebugLogger.log('cache-empty', scope: 'models/cache');
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'cache-load-failed',
|
'cache-load-failed',
|
||||||
@@ -1012,14 +1011,8 @@ class Conversations extends _$Conversations {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
DebugLogger.log(
|
|
||||||
'cache-restored',
|
|
||||||
scope: 'conversations/cache',
|
|
||||||
data: {'count': sortedCached.length},
|
|
||||||
);
|
|
||||||
return sortedCached;
|
return sortedCached;
|
||||||
}
|
}
|
||||||
DebugLogger.log('cache-empty', scope: 'conversations/cache');
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'cache-load-failed',
|
'cache-load-failed',
|
||||||
@@ -1125,11 +1118,6 @@ class Conversations extends _$Conversations {
|
|||||||
Future<void>(() async {
|
Future<void>(() async {
|
||||||
try {
|
try {
|
||||||
await storage.saveLocalConversations(conversations);
|
await storage.saveLocalConversations(conversations);
|
||||||
DebugLogger.log(
|
|
||||||
'cache-saved',
|
|
||||||
scope: 'conversations/cache',
|
|
||||||
data: {'count': conversations.length},
|
|
||||||
);
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'cache-save-failed',
|
'cache-save-failed',
|
||||||
@@ -1205,22 +1193,8 @@ class Conversations extends _$Conversations {
|
|||||||
|
|
||||||
final conversationToFolder = <String, String>{};
|
final conversationToFolder = <String, String>{};
|
||||||
for (final folder in folders) {
|
for (final folder in folders) {
|
||||||
DebugLogger.log(
|
|
||||||
'folder',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {
|
|
||||||
'id': folder.id,
|
|
||||||
'name': folder.name,
|
|
||||||
'count': folder.conversationIds.length,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
for (final conversationId in folder.conversationIds) {
|
for (final conversationId in folder.conversationIds) {
|
||||||
conversationToFolder[conversationId] = folder.id;
|
conversationToFolder[conversationId] = folder.id;
|
||||||
DebugLogger.log(
|
|
||||||
'map',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {'conversationId': conversationId, 'folderId': folder.id},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,15 +1208,6 @@ class Conversations extends _$Conversations {
|
|||||||
conversationMap[conversation.id] = conversation.copyWith(
|
conversationMap[conversation.id] = conversation.copyWith(
|
||||||
folderId: folderIdToUse,
|
folderId: folderIdToUse,
|
||||||
);
|
);
|
||||||
DebugLogger.log(
|
|
||||||
'update-folder',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {
|
|
||||||
'conversationId': conversation.id,
|
|
||||||
'folderId': folderIdToUse,
|
|
||||||
'explicit': explicitFolderId != null,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
conversationMap[conversation.id] = conversation;
|
conversationMap[conversation.id] = conversation;
|
||||||
}
|
}
|
||||||
@@ -1261,8 +1226,6 @@ class Conversations extends _$Conversations {
|
|||||||
'preview': missingInBase.take(5).toList(),
|
'preview': missingInBase.take(5).toList(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
DebugLogger.log('folders-synced', scope: 'conversations/map');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final folder in folders) {
|
for (final folder in folders) {
|
||||||
@@ -1311,11 +1274,6 @@ class Conversations extends _$Conversations {
|
|||||||
: fetched;
|
: fetched;
|
||||||
conversationMap[toAdd.id] = toAdd;
|
conversationMap[toAdd.id] = toAdd;
|
||||||
existingIds.add(toAdd.id);
|
existingIds.add(toAdd.id);
|
||||||
DebugLogger.log(
|
|
||||||
'add-missing',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {'conversationId': toAdd.id, 'folderId': folder.id},
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
final placeholder = Conversation(
|
final placeholder = Conversation(
|
||||||
id: convId,
|
id: convId,
|
||||||
@@ -1327,11 +1285,6 @@ class Conversations extends _$Conversations {
|
|||||||
);
|
);
|
||||||
conversationMap[convId] = placeholder;
|
conversationMap[convId] = placeholder;
|
||||||
existingIds.add(convId);
|
existingIds.add(convId);
|
||||||
DebugLogger.log(
|
|
||||||
'add-placeholder',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {'conversationId': convId, 'folderId': folder.id},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1342,11 +1295,6 @@ class Conversations extends _$Conversations {
|
|||||||
: conv;
|
: conv;
|
||||||
conversationMap[toAdd.id] = toAdd;
|
conversationMap[toAdd.id] = toAdd;
|
||||||
existingIds.add(toAdd.id);
|
existingIds.add(toAdd.id);
|
||||||
DebugLogger.log(
|
|
||||||
'add-folder-fetch',
|
|
||||||
scope: 'conversations/map',
|
|
||||||
data: {'conversationId': toAdd.id, 'folderId': folder.id},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1354,11 +1302,6 @@ class Conversations extends _$Conversations {
|
|||||||
final sortedConversations = _sortByUpdatedAt(
|
final sortedConversations = _sortByUpdatedAt(
|
||||||
conversationMap.values.toList(),
|
conversationMap.values.toList(),
|
||||||
);
|
);
|
||||||
DebugLogger.log(
|
|
||||||
'sort',
|
|
||||||
scope: 'conversations',
|
|
||||||
data: {'source': 'folder-sync'},
|
|
||||||
);
|
|
||||||
_updateCacheTimestamp(DateTime.now());
|
_updateCacheTimestamp(DateTime.now());
|
||||||
return sortedConversations;
|
return sortedConversations;
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
@@ -2083,11 +2026,6 @@ class Folders extends _$Folders {
|
|||||||
final storage = ref.watch(optimizedStorageServiceProvider);
|
final storage = ref.watch(optimizedStorageServiceProvider);
|
||||||
final cached = await storage.getLocalFolders();
|
final cached = await storage.getLocalFolders();
|
||||||
if (cached.isNotEmpty) {
|
if (cached.isNotEmpty) {
|
||||||
DebugLogger.log(
|
|
||||||
'cache-restored',
|
|
||||||
scope: 'folders/cache',
|
|
||||||
data: {'count': cached.length},
|
|
||||||
);
|
|
||||||
Future.microtask(() async {
|
Future.microtask(() async {
|
||||||
try {
|
try {
|
||||||
await refresh();
|
await refresh();
|
||||||
@@ -2103,7 +2041,6 @@ class Folders extends _$Folders {
|
|||||||
return _sort(cached);
|
return _sort(cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.log('cache-empty', scope: 'folders/cache');
|
|
||||||
final api = ref.watch(apiServiceProvider);
|
final api = ref.watch(apiServiceProvider);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
DebugLogger.warning('api-missing', scope: 'folders');
|
DebugLogger.warning('api-missing', scope: 'folders');
|
||||||
|
|||||||
@@ -344,10 +344,6 @@ class OptimizedStorageService {
|
|||||||
'items': jsonReady,
|
'items': jsonReady,
|
||||||
}, debugLabel: 'encode_local_conversations');
|
}, debugLabel: 'encode_local_conversations');
|
||||||
await _cachesBox.put(_localConversationsKey, serialized);
|
await _cachesBox.put(_localConversationsKey, serialized);
|
||||||
DebugLogger.log(
|
|
||||||
'Saved ${conversations.length} local conversations',
|
|
||||||
scope: 'storage/optimized',
|
|
||||||
);
|
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'Failed to save local conversations',
|
'Failed to save local conversations',
|
||||||
@@ -390,10 +386,6 @@ class OptimizedStorageService {
|
|||||||
'items': jsonReady,
|
'items': jsonReady,
|
||||||
}, debugLabel: 'encode_local_folders');
|
}, debugLabel: 'encode_local_folders');
|
||||||
await _cachesBox.put(_localFoldersKey, serialized);
|
await _cachesBox.put(_localFoldersKey, serialized);
|
||||||
DebugLogger.log(
|
|
||||||
'Saved ${folders.length} local folders',
|
|
||||||
scope: 'storage/optimized',
|
|
||||||
);
|
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'Failed to save local folders',
|
'Failed to save local folders',
|
||||||
@@ -436,7 +428,6 @@ class OptimizedStorageService {
|
|||||||
}
|
}
|
||||||
final serialized = jsonEncode(user.toJson());
|
final serialized = jsonEncode(user.toJson());
|
||||||
await _cachesBox.put(_localUserKey, serialized);
|
await _cachesBox.put(_localUserKey, serialized);
|
||||||
DebugLogger.log('Saved local user profile', scope: 'storage/optimized');
|
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'Failed to save local user',
|
'Failed to save local user',
|
||||||
@@ -649,10 +640,6 @@ class OptimizedStorageService {
|
|||||||
'items': jsonReady,
|
'items': jsonReady,
|
||||||
}, debugLabel: 'encode_local_models');
|
}, debugLabel: 'encode_local_models');
|
||||||
await _cachesBox.put(_localModelsKey, _wrapServerScoped(serialized));
|
await _cachesBox.put(_localModelsKey, _wrapServerScoped(serialized));
|
||||||
DebugLogger.log(
|
|
||||||
'Saved ${models.length} local models',
|
|
||||||
scope: 'storage/optimized',
|
|
||||||
);
|
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'Failed to save local models',
|
'Failed to save local models',
|
||||||
@@ -699,10 +686,6 @@ class OptimizedStorageService {
|
|||||||
'items': jsonReady,
|
'items': jsonReady,
|
||||||
}, debugLabel: 'encode_local_tools');
|
}, debugLabel: 'encode_local_tools');
|
||||||
await _cachesBox.put(_localToolsKey, _wrapServerScoped(serialized));
|
await _cachesBox.put(_localToolsKey, _wrapServerScoped(serialized));
|
||||||
DebugLogger.log(
|
|
||||||
'Saved ${tools.length} local tools',
|
|
||||||
scope: 'storage/optimized',
|
|
||||||
);
|
|
||||||
} catch (error, stack) {
|
} catch (error, stack) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'Failed to save local tools',
|
'Failed to save local tools',
|
||||||
|
|||||||
@@ -19,13 +19,7 @@ typedef WorkerTask<Q, R> = ComputeCallback<Q, R>;
|
|||||||
/// synchronously because secondary isolates are not supported.
|
/// synchronously because secondary isolates are not supported.
|
||||||
class WorkerManager {
|
class WorkerManager {
|
||||||
WorkerManager({int maxConcurrentTasks = _defaultMaxConcurrentTasks})
|
WorkerManager({int maxConcurrentTasks = _defaultMaxConcurrentTasks})
|
||||||
: _maxConcurrentTasks = math.max(1, maxConcurrentTasks) {
|
: _maxConcurrentTasks = math.max(1, maxConcurrentTasks);
|
||||||
DebugLogger.log(
|
|
||||||
'initialized',
|
|
||||||
scope: 'worker',
|
|
||||||
data: {'max': _maxConcurrentTasks},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int _defaultMaxConcurrentTasks = 2;
|
static const int _defaultMaxConcurrentTasks = 2;
|
||||||
|
|
||||||
@@ -73,18 +67,6 @@ class WorkerManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
_pendingJobs.add(job);
|
_pendingJobs.add(job);
|
||||||
|
|
||||||
DebugLogger.log(
|
|
||||||
'queued',
|
|
||||||
scope: 'worker',
|
|
||||||
data: {
|
|
||||||
'id': jobId,
|
|
||||||
if (debugLabel != null) 'label': debugLabel,
|
|
||||||
'pending': _pendingJobs.length,
|
|
||||||
'active': _activeJobs,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
_processQueue();
|
_processQueue();
|
||||||
|
|
||||||
return completer.future;
|
return completer.future;
|
||||||
@@ -104,7 +86,6 @@ class WorkerManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.log('disposed', scope: 'worker', data: {'active': _activeJobs});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _processQueue() {
|
void _processQueue() {
|
||||||
@@ -120,17 +101,6 @@ class WorkerManager {
|
|||||||
|
|
||||||
void _startJob(_EnqueuedJob job) {
|
void _startJob(_EnqueuedJob job) {
|
||||||
_activeJobs++;
|
_activeJobs++;
|
||||||
|
|
||||||
DebugLogger.log(
|
|
||||||
'started',
|
|
||||||
scope: 'worker',
|
|
||||||
data: {
|
|
||||||
'id': job.id,
|
|
||||||
if (job.debugLabel != null) 'label': job.debugLabel,
|
|
||||||
'active': _activeJobs,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
unawaited(_runJob(job));
|
unawaited(_runJob(job));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,16 +108,6 @@ class WorkerManager {
|
|||||||
try {
|
try {
|
||||||
final result = await job.run();
|
final result = await job.run();
|
||||||
job.onComplete(result);
|
job.onComplete(result);
|
||||||
|
|
||||||
DebugLogger.log(
|
|
||||||
'completed',
|
|
||||||
scope: 'worker',
|
|
||||||
data: {
|
|
||||||
'id': job.id,
|
|
||||||
if (job.debugLabel != null) 'label': job.debugLabel,
|
|
||||||
'pending': _pendingJobs.length,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
job.onError(error, stackTrace);
|
job.onError(error, stackTrace);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user