From 2275ef2aed25f0174a83e66e3ffb9abdeade2152 Mon Sep 17 00:00:00 2001 From: ion-endymion <188437551+ice-endymion@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:38:22 +0100 Subject: [PATCH] refactor: change Logger to singleton --- .../onboarding_complete_notifier.c.dart | 2 +- .../message_item_wrapper.dart | 2 +- .../components/more_content_view.dart | 2 +- ...nversation_message_actions_provider.c.dart | 14 +++++------ ...rsation_message_management_provider.c.dart | 22 ++++++++--------- .../core/providers/dio_provider.c.dart | 2 +- .../core/providers/init_provider.c.dart | 2 +- .../core/views/pages/error_modal.dart | 2 +- lib/app/features/debug/views/debug_page.dart | 2 +- .../create_post_modal/hooks/use_has_poll.dart | 2 +- .../suggestions_notifier_provider.c.dart | 2 +- .../gallery/providers/camera_provider.c.dart | 16 ++++++------- .../gallery/providers/gallery_provider.c.dart | 2 +- .../nostr/providers/nostr_notifier.c.dart | 2 +- .../user/providers/user_relays_manager.c.dart | 2 +- .../providers/go_router_provider.c.dart | 2 +- .../audio_wave_playback_service.c.dart | 4 ++-- lib/app/services/browser/browser.dart | 2 +- .../compressor/compress_service.c.dart | 18 +++++++------- .../ion_identity/ion_identity_provider.c.dart | 2 +- lib/app/services/logger/logger.dart | 24 ++++++++++++------- .../services/media_service/album_service.dart | 2 +- .../media_service/banuba_service.c.dart | 6 ++--- .../media_service/media_service.c.dart | 4 ++-- lib/app/services/nostr/nostr_logger.dart | 8 +++---- lib/app/utils/retry.dart | 4 ++-- 26 files changed, 79 insertions(+), 73 deletions(-) diff --git a/lib/app/features/auth/providers/onboarding_complete_notifier.c.dart b/lib/app/features/auth/providers/onboarding_complete_notifier.c.dart index 08f8d044c..18c345385 100644 --- a/lib/app/features/auth/providers/onboarding_complete_notifier.c.dart +++ b/lib/app/features/auth/providers/onboarding_complete_notifier.c.dart @@ -205,7 +205,7 @@ class OnboardingCompleteNotifier extends _$OnboardingCompleteNotifier { } } catch (error, stackTrace) { // intentionally ignore upload avatar exceptions - Logger.log('Upload avatar exception', error: error, stackTrace: stackTrace); + Logger().log('Upload avatar exception', error: error, stackTrace: stackTrace); } return null; } diff --git a/lib/app/features/chat/messages/views/components/message_item_wrapper/message_item_wrapper.dart b/lib/app/features/chat/messages/views/components/message_item_wrapper/message_item_wrapper.dart index 8ddee2b7d..3cd792b4b 100644 --- a/lib/app/features/chat/messages/views/components/message_item_wrapper/message_item_wrapper.dart +++ b/lib/app/features/chat/messages/views/components/message_item_wrapper/message_item_wrapper.dart @@ -41,7 +41,7 @@ class MessageItemWrapper extends HookWidget { ), ); } catch (e, st) { - Logger.log('Error showing message reaction dialog:', error: e, stackTrace: st); + Logger().log('Error showing message reaction dialog:', error: e, stackTrace: st); } }, [messageItemKey, isMe], diff --git a/lib/app/features/chat/messages/views/components/messaging_bottom_bar/components/more_content_view.dart b/lib/app/features/chat/messages/views/components/messaging_bottom_bar/components/more_content_view.dart index 52b2fb0d8..a76c11666 100644 --- a/lib/app/features/chat/messages/views/components/messaging_bottom_bar/components/more_content_view.dart +++ b/lib/app/features/chat/messages/views/components/messaging_bottom_bar/components/more_content_view.dart @@ -54,7 +54,7 @@ class MoreContentView extends ConsumerWidget { ).push(context); //TODO: use contactId to share profile - Logger.log(contactId ?? 'No contact selected'); + Logger().log(contactId ?? 'No contact selected'); ref.read(messagingBottomBarActiveStateProvider.notifier).setText(); }, diff --git a/lib/app/features/chat/providers/conversation_message_actions_provider.c.dart b/lib/app/features/chat/providers/conversation_message_actions_provider.c.dart index f4062f696..045cb15b4 100644 --- a/lib/app/features/chat/providers/conversation_message_actions_provider.c.dart +++ b/lib/app/features/chat/providers/conversation_message_actions_provider.c.dart @@ -87,7 +87,7 @@ class ConversationMessageActionsService { ['encrypted'], ]; - Logger.log('Encoded rumor $encodedRumor'); + Logger().log('Encoded rumor $encodedRumor'); final encryptedRumor = await Nip44.encryptMessage( encodedRumor, @@ -95,7 +95,7 @@ class ConversationMessageActionsService { receiverPubkey, ); - Logger.log('Encrypted rumor $encryptedRumor'); + Logger().log('Encrypted rumor $encryptedRumor'); final id = EventMessage.calculateEventId( tags: tags, @@ -115,7 +115,7 @@ class ConversationMessageActionsService { sig: null, ); - Logger.log('Bookmark message $bookmarkMessage'); + Logger().log('Bookmark message $bookmarkMessage'); await nostrNotifier.sendEvent(bookmarkMessage, cache: false); } @@ -211,7 +211,7 @@ class ConversationMessageActionsService { sig: await signer.sign(message: id), ); - Logger.log('Event message $eventMessage'); + Logger().log('Event message $eventMessage'); final seal = await sealService.createSeal( eventMessage, @@ -219,7 +219,7 @@ class ConversationMessageActionsService { receiverPubkey, ); - Logger.log('Seal message $seal'); + Logger().log('Seal message $seal'); final expirationTag = EntityExpiration( value: DateTime.now().add( @@ -235,11 +235,11 @@ class ConversationMessageActionsService { expirationTag: expirationTag, ); - Logger.log('Wrap message $wrap'); + Logger().log('Wrap message $wrap'); final result = await nostrNotifier.sendEvent(wrap, cache: false); - Logger.log('Sent message $result'); + Logger().log('Sent message $result'); return result; } diff --git a/lib/app/features/chat/providers/conversation_message_management_provider.c.dart b/lib/app/features/chat/providers/conversation_message_management_provider.c.dart index 006a09673..4a4967b70 100644 --- a/lib/app/features/chat/providers/conversation_message_management_provider.c.dart +++ b/lib/app/features/chat/providers/conversation_message_management_provider.c.dart @@ -101,7 +101,7 @@ class ConversationMessageManagementService { alt: FileAlt.message, ); - Logger.log( + Logger().log( 'Uploaded media file: ${uploadResult.fileMetadata.url}, ${uploadResult.fileMetadata.mimeType} ${uploadResult.fileMetadata.size}', ); @@ -147,7 +147,7 @@ class ConversationMessageManagementService { final decryptedDecompressedFiles = []; for (final attachment in privateDirectMessageEntity.data.media.values) { - Logger.log('Attachment: $attachment'); + Logger().log('Attachment: $attachment'); if (attachment.encryptionKey != null && attachment.encryptionNonce != null && attachment.encryptionMac != null) { @@ -157,7 +157,7 @@ class ConversationMessageManagementService { final file = await fileCacheService.getFile(attachment.url); - Logger.log( + Logger().log( 'Downloaded encrypted media file: ${file.path}, ${attachment.mimeType} ${file.lengthSync()}', ); @@ -184,7 +184,7 @@ class ConversationMessageManagementService { fileExtension: attachment.mimeType.split('/').last, ); - Logger.log( + Logger().log( 'Decrypted media file: ${decryptedFile.path}, ${attachment.mimeType} ${decryptedFile.lengthSync()}', ); @@ -238,7 +238,7 @@ class ConversationMessageManagementService { sig: null, ); - Logger.log('Event message $eventMessage'); + Logger().log('Event message $eventMessage'); final seal = await sealService.createSeal( eventMessage, @@ -246,7 +246,7 @@ class ConversationMessageManagementService { receiverPubkey, ); - Logger.log('Seal message $seal'); + Logger().log('Seal message $seal'); final wrap = await wrapService.createWrap( seal, @@ -255,11 +255,11 @@ class ConversationMessageManagementService { PrivateDirectMessageEntity.kind, ); - Logger.log('Wrap message $wrap'); + Logger().log('Wrap message $wrap'); final result = await nostrNotifier.sendEvent(wrap, cache: false); - Logger.log('Sent message $result'); + Logger().log('Sent message $result'); return result; } @@ -273,7 +273,7 @@ class ConversationMessageManagementService { mediaFiles.map( (mediaFile) async { final size = File(mediaFile.path).lengthSync(); - Logger.log( + Logger().log( 'Original media file: ${mediaFile.path}, ${mediaFile.mimeType} $size', ); @@ -298,7 +298,7 @@ class ConversationMessageManagementService { }; final compressedSize = File(compressedMediaFile.path).lengthSync(); - Logger.log( + Logger().log( 'Compressed media file: ${compressedMediaFile.path}, ${compressedMediaFile.mimeType} $compressedSize', ); @@ -342,7 +342,7 @@ class ConversationMessageManagementService { mimeType: compressedMediaFile.mimeType, ); - Logger.log( + Logger().log( 'Encrypted media file ${compressedEncryptedMediaFile.mimeType} ${compressedEncryptedFile.lengthSync()}', ); diff --git a/lib/app/features/core/providers/dio_provider.c.dart b/lib/app/features/core/providers/dio_provider.c.dart index 583bda8db..f0aab814a 100644 --- a/lib/app/features/core/providers/dio_provider.c.dart +++ b/lib/app/features/core/providers/dio_provider.c.dart @@ -11,7 +11,7 @@ part 'dio_provider.c.g.dart'; Dio dio(Ref ref) { final dio = Dio(); - final logger = Logger.talkerDioLogger; + final logger = Logger().talkerDioLogger; if (logger != null) { dio.interceptors.add(logger); diff --git a/lib/app/features/core/providers/init_provider.c.dart b/lib/app/features/core/providers/init_provider.c.dart index 87d1f24c3..d2dceae71 100644 --- a/lib/app/features/core/providers/init_provider.c.dart +++ b/lib/app/features/core/providers/init_provider.c.dart @@ -23,7 +23,7 @@ Future initApp(Ref ref) async { final logApp = featureFlagsNotifier.get(LoggerFeatureFlag.logApp); final logNostrDart = featureFlagsNotifier.get(LoggerFeatureFlag.logNostrDart); - if (logApp) Logger.init(); + if (logApp) Logger().init(); Nostr.initialize(logNostrDart ? NostrLogger() : null); diff --git a/lib/app/features/core/views/pages/error_modal.dart b/lib/app/features/core/views/pages/error_modal.dart index 66bff2f49..55978fed7 100644 --- a/lib/app/features/core/views/pages/error_modal.dart +++ b/lib/app/features/core/views/pages/error_modal.dart @@ -15,7 +15,7 @@ import 'package:ion/generated/assets.gen.dart'; class ErrorModal extends ConsumerWidget { ErrorModal({required this.error, super.key}) { - Logger.error(error); + Logger().error(error); } final Object error; diff --git a/lib/app/features/debug/views/debug_page.dart b/lib/app/features/debug/views/debug_page.dart index ab259ff8c..2f620342d 100644 --- a/lib/app/features/debug/views/debug_page.dart +++ b/lib/app/features/debug/views/debug_page.dart @@ -15,7 +15,7 @@ class DebugPage extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final featureFlags = ref.watch(featureFlagsProvider); - final talker = Logger.talker; + final talker = Logger().talker; return Column( mainAxisSize: MainAxisSize.min, diff --git a/lib/app/features/feed/create_post/views/pages/create_post_modal/hooks/use_has_poll.dart b/lib/app/features/feed/create_post/views/pages/create_post_modal/hooks/use_has_poll.dart index 4a92a9438..9356ac666 100644 --- a/lib/app/features/feed/create_post/views/pages/create_post_modal/hooks/use_has_poll.dart +++ b/lib/app/features/feed/create_post/views/pages/create_post_modal/hooks/use_has_poll.dart @@ -58,7 +58,7 @@ bool _containsPollKey(dynamic customData) { try { parsedData = jsonDecode(customData) as Map?; } catch (e) { - Logger.log('Failed to parse custom data: $e'); + Logger().log('Failed to parse custom data: $e'); } } diff --git a/lib/app/features/feed/providers/article/suggestions_notifier_provider.c.dart b/lib/app/features/feed/providers/article/suggestions_notifier_provider.c.dart index 9d659ce2f..43b5c4486 100644 --- a/lib/app/features/feed/providers/article/suggestions_notifier_provider.c.dart +++ b/lib/app/features/feed/providers/article/suggestions_notifier_provider.c.dart @@ -27,7 +27,7 @@ class SuggestionsNotifier extends _$SuggestionsNotifier { newSuggestions = await ref.read(mentionSuggestionsProvider(query).future); } } catch (error) { - Logger.log('Error fetching suggestions: $error'); + Logger().log('Error fetching suggestions: $error'); } state = newSuggestions; diff --git a/lib/app/features/gallery/providers/camera_provider.c.dart b/lib/app/features/gallery/providers/camera_provider.c.dart index 6ee1d7ad1..32f70bdf3 100644 --- a/lib/app/features/gallery/providers/camera_provider.c.dart +++ b/lib/app/features/gallery/providers/camera_provider.c.dart @@ -66,7 +66,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { final initialCamera = _backCamera ?? _frontCamera; if (initialCamera == null) { - Logger.log('Camera not found'); + Logger().log('Camera not found'); state = const CameraState.error(message: 'Camera not found'); return; } @@ -74,7 +74,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { final controller = await _createCameraController(initialCamera); state = CameraState.ready(controller: controller); } catch (e) { - Logger.log('Camera initialization error: $e'); + Logger().log('Camera initialization error: $e'); state = CameraState.error(message: 'Camera initialization error: $e'); } } @@ -90,7 +90,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { _cameraController?.addListener(_onCameraControllerUpdate); return _cameraController!; } catch (e) { - Logger.log('Camera initialization error: $e'); + Logger().log('Camera initialization error: $e'); await _disposeCamera(); throw Exception('Camera initialization error: $e'); } @@ -154,7 +154,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { isFlashOn: mode == FlashMode.torch, ); } catch (e) { - Logger.log('Error setting flash mode', error: e); + Logger().log('Error setting flash mode', error: e); state = CameraState.error(message: 'Error setting flash mode: $e'); } }, @@ -174,7 +174,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { isFlashOn: !isFlashOn, ); } catch (e) { - Logger.log('Error toggling flash mode', error: e); + Logger().log('Error toggling flash mode', error: e); state = CameraState.error(message: 'Error toggling flash mode: $e'); } }, @@ -189,7 +189,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { final picture = await _cameraController!.takePicture(); return picture; } catch (e) { - Logger.log('Error taking picture', error: e); + Logger().log('Error taking picture', error: e); return null; } } @@ -206,7 +206,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { isFlashOn: isFlashOn, ); } catch (e) { - Logger.log('Error starting video recording', error: e); + Logger().log('Error starting video recording', error: e); state = CameraState.error(message: 'Error starting video recording: $e'); } } @@ -240,7 +240,7 @@ class CameraControllerNotifier extends _$CameraControllerNotifier { return videoFile; } catch (e) { - Logger.log('Error stopping video recording', error: e); + Logger().log('Error stopping video recording', error: e); state = CameraState.error(message: 'Error stopping video recording: $e'); return null; } diff --git a/lib/app/features/gallery/providers/gallery_provider.c.dart b/lib/app/features/gallery/providers/gallery_provider.c.dart index 45a6a0d64..fab286d49 100644 --- a/lib/app/features/gallery/providers/gallery_provider.c.dart +++ b/lib/app/features/gallery/providers/gallery_provider.c.dart @@ -53,7 +53,7 @@ class GalleryNotifier extends _$GalleryNotifier { final hasPermission = ref.read(hasPermissionProvider(Permission.photos)); if (!hasPermission) { - Logger.log('Photos Permission denied'); + Logger().log('Photos Permission denied'); return GalleryState( mediaData: [], currentPage: 0, diff --git a/lib/app/features/nostr/providers/nostr_notifier.c.dart b/lib/app/features/nostr/providers/nostr_notifier.c.dart index d5d4c4f39..6f48ba542 100644 --- a/lib/app/features/nostr/providers/nostr_notifier.c.dart +++ b/lib/app/features/nostr/providers/nostr_notifier.c.dart @@ -173,7 +173,7 @@ class NostrNotifier extends _$NostrNotifier { try { yield _parseAndCache(event); } catch (error, stackTrace) { - Logger.log('Failed to process event ${event.id}', error: error, stackTrace: stackTrace); + Logger().log('Failed to process event ${event.id}', error: error, stackTrace: stackTrace); } } } diff --git a/lib/app/features/user/providers/user_relays_manager.c.dart b/lib/app/features/user/providers/user_relays_manager.c.dart index 6bc63c640..bd1a50f1f 100644 --- a/lib/app/features/user/providers/user_relays_manager.c.dart +++ b/lib/app/features/user/providers/user_relays_manager.c.dart @@ -91,7 +91,7 @@ class UserRelaysManager extends _$UserRelaysManager { try { return await ionIdentity.users.details(userId: pubkey); } catch (error, stackTrace) { - Logger.log('Error fetching user relays', error: error, stackTrace: stackTrace); + Logger().log('Error fetching user relays', error: error, stackTrace: stackTrace); } }), ); diff --git a/lib/app/router/providers/go_router_provider.c.dart b/lib/app/router/providers/go_router_provider.c.dart index 8cec5edf8..3405526d5 100644 --- a/lib/app/router/providers/go_router_provider.c.dart +++ b/lib/app/router/providers/go_router_provider.c.dart @@ -36,7 +36,7 @@ GoRouter goRouter(Ref ref) { final isInitError = initState.hasError; if (isInitError) { - Logger.log('Init error', error: initState.error); + Logger().log('Init error', error: initState.error); return ErrorRoute().location; } diff --git a/lib/app/services/audio_wave_playback_service/audio_wave_playback_service.c.dart b/lib/app/services/audio_wave_playback_service/audio_wave_playback_service.c.dart index 8fb6ffbeb..3eebff484 100644 --- a/lib/app/services/audio_wave_playback_service/audio_wave_playback_service.c.dart +++ b/lib/app/services/audio_wave_playback_service/audio_wave_playback_service.c.dart @@ -33,7 +33,7 @@ class AudioWavePlaybackService { await preparePlayer(savedFilePath, audioPlaybackController, playerWaveStyle); } } catch (e, s) { - Logger.log('Error initializing player', error: e, stackTrace: s); + Logger().log('Error initializing player', error: e, stackTrace: s); } } @@ -48,7 +48,7 @@ class AudioWavePlaybackService { noOfSamples: playerWaveStyle.getSamplesForWidth(158.0.s), ); } catch (e, s) { - Logger.log('Error preparing player', error: e, stackTrace: s); + Logger().log('Error preparing player', error: e, stackTrace: s); } } diff --git a/lib/app/services/browser/browser.dart b/lib/app/services/browser/browser.dart index b7fc28233..6a47ad6d7 100644 --- a/lib/app/services/browser/browser.dart +++ b/lib/app/services/browser/browser.dart @@ -15,7 +15,7 @@ Future openUrl( return false; } } catch (error) { - Logger.log('Could not launch $url', error: error); + Logger().log('Could not launch $url', error: error); return false; } } diff --git a/lib/app/services/compressor/compress_service.c.dart b/lib/app/services/compressor/compress_service.c.dart index f8f49192d..0c2a65709 100644 --- a/lib/app/services/compressor/compress_service.c.dart +++ b/lib/app/services/compressor/compress_service.c.dart @@ -84,13 +84,13 @@ class CompressionService { final match = RegExp(r'Stream.*Video:.* (\d+)x(\d+)').firstMatch(logs); if (match == null) { - Logger.log('Failed to compress video. Dimension not found. Logs: $logs'); + Logger().log('Failed to compress video. Dimension not found. Logs: $logs'); throw CompressVideoException('no-dim'); } if (!ReturnCode.isSuccess(returnCode)) { final stackTrace = await session.getFailStackTrace(); - Logger.log('Failed to compress video. Logs: $logs, StackTrace: $stackTrace'); + Logger().log('Failed to compress video. Logs: $logs, StackTrace: $stackTrace'); throw CompressVideoException(returnCode); } @@ -101,7 +101,7 @@ class CompressionService { height: int.parse(match.group(2)!), ); } catch (error, stackTrace) { - Logger.log('Error during video compression!', error: error, stackTrace: stackTrace); + Logger().log('Error during video compression!', error: error, stackTrace: stackTrace); rethrow; } } @@ -144,7 +144,7 @@ class CompressionService { height: outputDimension.height, ); } catch (error, stackTrace) { - Logger.log('Error during image compression!', error: error, stackTrace: stackTrace); + Logger().log('Error during image compression!', error: error, stackTrace: stackTrace); rethrow; } } @@ -169,7 +169,7 @@ class CompressionService { } final logs = await session.getAllLogsAsString(); final stackTrace = await session.getFailStackTrace(); - Logger.log('Failed to convert audio to opus. Logs: $logs, StackTrace: $stackTrace'); + Logger().log('Failed to convert audio to opus. Logs: $logs, StackTrace: $stackTrace'); throw CompressAudioException(); }); } @@ -195,7 +195,7 @@ class CompressionService { } final logs = await session.getAllLogsAsString(); final stackTrace = await session.getFailStackTrace(); - Logger.log('Failed to convert audio to wav. Logs: $logs, StackTrace: $stackTrace'); + Logger().log('Failed to convert audio to wav. Logs: $logs, StackTrace: $stackTrace'); throw CompressAudioToWavException(); }); } @@ -246,7 +246,7 @@ class CompressionService { return compressedImage; } catch (error, stackTrace) { - Logger.log('Error during thumbnail extraction!', error: error, stackTrace: stackTrace); + Logger().log('Error during thumbnail extraction!', error: error, stackTrace: stackTrace); rethrow; } } @@ -271,7 +271,7 @@ class CompressionService { return _saveBytesIntoFile(bytes: compressedData, extension: 'br'); } catch (error, stackTrace) { - Logger.log('Error during Brotli compression!', error: error, stackTrace: stackTrace); + Logger().log('Error during Brotli compression!', error: error, stackTrace: stackTrace); throw CompressWithBrotliException(); } } @@ -287,7 +287,7 @@ class CompressionService { ); return _saveBytesIntoFile(bytes: decompressedData, extension: outputExtension); } catch (error, stackTrace) { - Logger.log('Error during Brotli decompression!', error: error, stackTrace: stackTrace); + Logger().log('Error during Brotli decompression!', error: error, stackTrace: stackTrace); throw DecompressBrotliException(); } } diff --git a/lib/app/services/ion_identity/ion_identity_provider.c.dart b/lib/app/services/ion_identity/ion_identity_provider.c.dart index aa2074fc0..d13b41237 100644 --- a/lib/app/services/ion_identity/ion_identity_provider.c.dart +++ b/lib/app/services/ion_identity/ion_identity_provider.c.dart @@ -26,7 +26,7 @@ Future> ionIdentity(Ref ref) async { final config = IONIdentityConfig( appId: appId, origin: env.get(EnvVariable.ION_ORIGIN), - logger: logIonIdentityClient ? Logger.talkerDioLogger : null, + logger: logIonIdentityClient ? Logger().talkerDioLogger : null, ); final ionClient = IONIdentity.createDefault(config: config); diff --git a/lib/app/services/logger/logger.dart b/lib/app/services/logger/logger.dart index 165125264..44806e691 100644 --- a/lib/app/services/logger/logger.dart +++ b/lib/app/services/logger/logger.dart @@ -5,17 +5,23 @@ import 'package:talker_dio_logger/talker_dio_logger_settings.dart'; import 'package:talker_flutter/talker_flutter.dart'; class Logger { + factory Logger() { + return _instance; + } + Logger._(); - static Talker? _talker; + static final Logger _instance = Logger._(); + + Talker? _talker; - static void init() { + Talker? get talker => _talker; + + void init() { _talker = TalkerFlutter.init(); } - static Talker? get talker => _talker; - - static TalkerDioLogger? get talkerDioLogger => TalkerDioLogger( + TalkerDioLogger? get talkerDioLogger => TalkerDioLogger( talker: talker, settings: TalkerDioLoggerSettings( printRequestHeaders: true, @@ -26,7 +32,7 @@ class Logger { ), ); - static void log( + void log( String message, { Object? error, StackTrace? stackTrace, @@ -38,15 +44,15 @@ class Logger { } } - static void info(String message) { + void info(String message) { _talker?.info(message); } - static void warning(String message) { + void warning(String message) { _talker?.warning(message); } - static void error( + void error( Object error, { StackTrace? stackTrace, }) { diff --git a/lib/app/services/media_service/album_service.dart b/lib/app/services/media_service/album_service.dart index 49f58b88e..cb201ccf3 100644 --- a/lib/app/services/media_service/album_service.dart +++ b/lib/app/services/media_service/album_service.dart @@ -49,7 +49,7 @@ class AlbumService { }) async { final assetPath = _albumsCache[albumId]; if (assetPath == null) { - Logger.log('Album not found in cache: $albumId'); + Logger().log('Album not found in cache: $albumId'); return []; } diff --git a/lib/app/services/media_service/banuba_service.c.dart b/lib/app/services/media_service/banuba_service.c.dart index 73d25b327..feae6c2a8 100644 --- a/lib/app/services/media_service/banuba_service.c.dart +++ b/lib/app/services/media_service/banuba_service.c.dart @@ -60,7 +60,7 @@ class BanubaService { } return filePath; } on PlatformException catch (e) { - Logger.log( + Logger().log( 'Start Photo Editor error', error: e, stackTrace: StackTrace.current, @@ -92,7 +92,7 @@ Future editMedia(Ref ref, MediaFile mediaFile) async { final filePath = await ref.read(assetFilePathProvider(mediaFile.path).future); if (filePath == null) { - Logger.log( + Logger().log( 'File path or mime type is null', error: mediaFile, stackTrace: StackTrace.current, @@ -101,7 +101,7 @@ Future editMedia(Ref ref, MediaFile mediaFile) async { } if (mediaFile.mimeType == null) { - Logger.log( + Logger().log( 'Mime type is null', error: mediaFile, stackTrace: StackTrace.current, diff --git a/lib/app/services/media_service/media_service.c.dart b/lib/app/services/media_service/media_service.c.dart index 454831f51..ff0c92b9c 100644 --- a/lib/app/services/media_service/media_service.c.dart +++ b/lib/app/services/media_service/media_service.c.dart @@ -88,7 +88,7 @@ class MediaService { return mediaFiles; } catch (e) { - Logger.log('Error fetching gallery images: $e'); + Logger().log('Error fetching gallery images: $e'); return []; } } @@ -198,7 +198,7 @@ class MediaService { } return null; } catch (e, st) { - Logger.log('Error capturing widget as image:', error: e, stackTrace: st); + Logger().log('Error capturing widget as image:', error: e, stackTrace: st); return null; } } diff --git a/lib/app/services/nostr/nostr_logger.dart b/lib/app/services/nostr/nostr_logger.dart index d17f2acc0..81654d689 100644 --- a/lib/app/services/nostr/nostr_logger.dart +++ b/lib/app/services/nostr/nostr_logger.dart @@ -8,19 +8,19 @@ class NostrLogger implements NostrDartLogger { @override void info(String message, [Object? error, StackTrace? stackTrace]) { - Logger.info('$_prefix $message'); + Logger().info('$_prefix $message'); if (error != null) { - Logger.error('$_prefix $error', stackTrace: stackTrace); + Logger().error('$_prefix $error', stackTrace: stackTrace); } } @override void warning(String message, [Object? error, StackTrace? stackTrace]) { - Logger.warning('$_prefix $message'); + Logger().warning('$_prefix $message'); if (error != null) { - Logger.error('$_prefix $error', stackTrace: stackTrace); + Logger().error('$_prefix $error', stackTrace: stackTrace); } } } diff --git a/lib/app/utils/retry.dart b/lib/app/utils/retry.dart index e4d238bdd..679a3498b 100644 --- a/lib/app/utils/retry.dart +++ b/lib/app/utils/retry.dart @@ -59,7 +59,7 @@ Stream withRetryStream( rethrow; } - Logger.log(e.toString()); + Logger().log(e.toString()); attempt++; if (attempt >= maxRetries) { rethrow; @@ -73,7 +73,7 @@ Stream withRetryStream( maxJitter: maxJitter, ); - Logger.log('Retry #$attempt after ${delay.inMilliseconds}ms...'); + Logger().log('Retry #$attempt after ${delay.inMilliseconds}ms...'); await Future.delayed(delay); } onRetry?.call();