-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Change of logging approach ## Additional Notes - Refactor logging to have one logger - Use logger interface from [NostrDart](https://github.com/ice-blockchain/nostr-dart/blob/master/lib/src/nostr_dart_logger.dart) to control logs from app - Use `TalkerDioLogger` as Interceptor for `ionIdentityClient` to control logs from app - Integrate [Talker](https://pub.dev/packages/talker) package for logs - Add Debug menu, shake 👋 your phone or use hotkeys in simulators(🤖 cmd+m, 🍏 ctrl+cmd+z) - Refactor feature flags (logs can be on/off by feature flags) - Now you can export logs and share them ## Type of Change - [ ] Bug fix - [x] New feature - [x] Breaking change - [x] Refactoring - [ ] Documentation - [ ] Chore ## Screenshots <img src="https://github.com/user-attachments/assets/cd08b7cd-b799-4e11-beea-005ccf5a992b" width="240"/> <img src="https://github.com/user-attachments/assets/f013d02f-6193-4b1d-9e48-7cf158ce3169" width="240"/> <img src="https://github.com/user-attachments/assets/b81732be-9c2f-4028-8ebf-c888813ebaf4" width="240"/>
- Loading branch information
1 parent
e487ee7
commit ada521e
Showing
34 changed files
with
421 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 15 additions & 48 deletions
63
lib/app/features/core/providers/feature_flags_provider.c.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,31 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import 'package:ion/app/features/core/model/feature_flags.dart'; | ||
import 'package:ion/app/services/logger/logger.dart'; | ||
import 'package:ion/app/features/core/providers/env_provider.c.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'feature_flags_provider.c.g.dart'; | ||
|
||
abstract class FeatureFlagsService { | ||
const FeatureFlagsService(); | ||
|
||
bool? get(FeatureFlag flag); | ||
|
||
Set<FeatureFlag> get supportedFlags; | ||
} | ||
|
||
final class LocalFeatureFlagsService extends FeatureFlagsService { | ||
factory LocalFeatureFlagsService() { | ||
return const LocalFeatureFlagsService._({ | ||
@Riverpod(keepAlive: true) | ||
class FeatureFlags extends _$FeatureFlags { | ||
@override | ||
Map<FeatureFlag, bool> build() { | ||
return { | ||
/// Local flags | ||
WalletFeatureFlag.buyNftEnabled: false, | ||
FeedFeatureFlag.showTrendingVideo: false, | ||
FeedFeatureFlag.showMentionsSuggestions: false, | ||
HideCreatorsWithoutPicture.hideCreatorsWithoutPicture: true, | ||
}); | ||
} | ||
|
||
const LocalFeatureFlagsService._(this._featuresMap); | ||
|
||
final Map<FeatureFlag, bool> _featuresMap; | ||
|
||
@override | ||
bool? get(FeatureFlag flag) => _featuresMap[flag]; | ||
|
||
@override | ||
Set<FeatureFlag> get supportedFlags => _featuresMap.keys.toSet(); | ||
} | ||
|
||
@Riverpod(keepAlive: true) | ||
class FeatureFlags extends _$FeatureFlags { | ||
late final Set<FeatureFlagsService> _services; | ||
|
||
@override | ||
Future<void> build() async { | ||
_services = { | ||
LocalFeatureFlagsService(), | ||
/// Log flags | ||
if (ref.watch(envProvider.notifier).get(EnvVariable.SHOW_DEBUG_INFO)) ...{ | ||
LoggerFeatureFlag.logApp: true, | ||
LoggerFeatureFlag.logRouters: false, | ||
LoggerFeatureFlag.logNostrDart: true, | ||
LoggerFeatureFlag.logIonIdentityClient: true, | ||
}, | ||
}; | ||
} | ||
|
||
bool get(FeatureFlag flag, {bool defaultValue = false}) { | ||
for (final service in _services) { | ||
if (service.supportedFlags.contains(flag)) { | ||
final value = service.get(flag); | ||
|
||
if (value != null) { | ||
return value; | ||
} | ||
} | ||
} | ||
|
||
Logger.log('${flag.key} not found.'); | ||
|
||
return defaultValue; | ||
} | ||
bool get(FeatureFlag flag) => state[flag] ?? false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:ion/app/extensions/extensions.dart'; | ||
import 'package:ion/app/features/core/providers/feature_flags_provider.c.dart'; | ||
import 'package:ion/app/router/components/navigation_app_bar/navigation_app_bar.dart'; | ||
import 'package:ion/app/router/components/navigation_app_bar/navigation_close_button.dart'; | ||
import 'package:ion/app/services/logger/logger.dart'; | ||
import 'package:talker_flutter/talker_flutter.dart'; | ||
|
||
class DebugPage extends ConsumerWidget { | ||
const DebugPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final featureFlags = ref.watch(featureFlagsProvider); | ||
final talker = Logger.talker; | ||
|
||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
NavigationAppBar.modal( | ||
title: const Text('🐞 Debug'), | ||
showBackButton: false, | ||
actions: const [NavigationCloseButton()], | ||
), | ||
Flexible( | ||
child: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: ListView( | ||
shrinkWrap: true, | ||
children: [ | ||
if (talker != null) | ||
Card( | ||
child: ListTile( | ||
leading: const Icon(Icons.bug_report), | ||
title: const Text('View Debug Logs'), | ||
subtitle: const Text('Check application logs and diagnostics'), | ||
trailing: const Icon(Icons.chevron_right), | ||
onTap: () => Navigator.of(context).push( | ||
MaterialPageRoute<TalkerScreen>( | ||
builder: (context) => TalkerScreen( | ||
talker: talker, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
SizedBox(height: 16.0.s), | ||
ExpansionTile( | ||
title: const Text('Feature Flags'), | ||
children: featureFlags.entries | ||
.map( | ||
(entry) => Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 4), | ||
child: ListTile( | ||
title: Text(entry.key.key), | ||
trailing: Icon( | ||
entry.value ? Icons.check_circle : Icons.cancel, | ||
color: entry.value ? Colors.green : Colors.red, | ||
), | ||
), | ||
), | ||
) | ||
.toList(), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.