Skip to content

Commit

Permalink
refactor: change Logger to singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-endymion committed Jan 9, 2025
1 parent a2410dd commit 2275ef2
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MoreContentView extends ConsumerWidget {
).push<String>(context);

//TODO: use contactId to share profile
Logger.log(contactId ?? 'No contact selected');
Logger().log(contactId ?? 'No contact selected');

ref.read(messagingBottomBarActiveStateProvider.notifier).setText();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ class ConversationMessageActionsService {
['encrypted'],
];

Logger.log('Encoded rumor $encodedRumor');
Logger().log('Encoded rumor $encodedRumor');

final encryptedRumor = await Nip44.encryptMessage(
encodedRumor,
eventSigner!.privateKey,
receiverPubkey,
);

Logger.log('Encrypted rumor $encryptedRumor');
Logger().log('Encrypted rumor $encryptedRumor');

final id = EventMessage.calculateEventId(
tags: tags,
Expand All @@ -115,7 +115,7 @@ class ConversationMessageActionsService {
sig: null,
);

Logger.log('Bookmark message $bookmarkMessage');
Logger().log('Bookmark message $bookmarkMessage');

await nostrNotifier.sendEvent(bookmarkMessage, cache: false);
}
Expand Down Expand Up @@ -211,15 +211,15 @@ class ConversationMessageActionsService {
sig: await signer.sign(message: id),
);

Logger.log('Event message $eventMessage');
Logger().log('Event message $eventMessage');

final seal = await sealService.createSeal(
eventMessage,
signer,
receiverPubkey,
);

Logger.log('Seal message $seal');
Logger().log('Seal message $seal');

final expirationTag = EntityExpiration(
value: DateTime.now().add(
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
);

Expand Down Expand Up @@ -147,7 +147,7 @@ class ConversationMessageManagementService {
final decryptedDecompressedFiles = <File>[];

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) {
Expand All @@ -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()}',
);

Expand All @@ -184,7 +184,7 @@ class ConversationMessageManagementService {
fileExtension: attachment.mimeType.split('/').last,
);

Logger.log(
Logger().log(
'Decrypted media file: ${decryptedFile.path}, ${attachment.mimeType} ${decryptedFile.lengthSync()}',
);

Expand Down Expand Up @@ -238,15 +238,15 @@ class ConversationMessageManagementService {
sig: null,
);

Logger.log('Event message $eventMessage');
Logger().log('Event message $eventMessage');

final seal = await sealService.createSeal(
eventMessage,
signer,
receiverPubkey,
);

Logger.log('Seal message $seal');
Logger().log('Seal message $seal');

final wrap = await wrapService.createWrap(
seal,
Expand All @@ -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;
}
Expand All @@ -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',
);

Expand All @@ -298,7 +298,7 @@ class ConversationMessageManagementService {
};

final compressedSize = File(compressedMediaFile.path).lengthSync();
Logger.log(
Logger().log(
'Compressed media file: ${compressedMediaFile.path}, ${compressedMediaFile.mimeType} $compressedSize',
);

Expand Down Expand Up @@ -342,7 +342,7 @@ class ConversationMessageManagementService {
mimeType: compressedMediaFile.mimeType,
);

Logger.log(
Logger().log(
'Encrypted media file ${compressedEncryptedMediaFile.mimeType} ${compressedEncryptedFile.lengthSync()}',
);

Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/core/providers/dio_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/core/providers/init_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Future<void> 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);

Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/core/views/pages/error_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/debug/views/debug_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool _containsPollKey(dynamic customData) {
try {
parsedData = jsonDecode(customData) as Map<String, dynamic>?;
} catch (e) {
Logger.log('Failed to parse custom data: $e');
Logger().log('Failed to parse custom data: $e');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions lib/app/features/gallery/providers/camera_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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;
}

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');
}
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -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');
}
},
Expand All @@ -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');
}
},
Expand All @@ -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;
}
}
Expand All @@ -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');
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/gallery/providers/gallery_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/nostr/providers/nostr_notifier.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/user/providers/user_relays_manager.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/router/providers/go_router_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/app/services/browser/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Future<bool> openUrl(
return false;
}
} catch (error) {
Logger.log('Could not launch $url', error: error);
Logger().log('Could not launch $url', error: error);
return false;
}
}
Expand Down
Loading

0 comments on commit 2275ef2

Please sign in to comment.