This commit is contained in:
Christien Rioux 2024-02-12 10:35:41 -05:00
parent 9dd17cb077
commit a551791f97
4 changed files with 39 additions and 7 deletions

1
devtools_options.yaml Normal file
View File

@ -0,0 +1 @@
extensions:

View File

@ -10,6 +10,7 @@ import 'account_manager/account_manager.dart';
import 'router/router.dart';
import 'settings/settings.dart';
import 'tick.dart';
import 'veilid_processor/veilid_processor.dart';
class VeilidChatApp extends StatelessWidget {
const VeilidChatApp({
@ -31,6 +32,9 @@ class VeilidChatApp extends StatelessWidget {
state: LocalizationProvider.of(context).state,
child: MultiBlocProvider(
providers: [
BlocProvider<ConnectionStateCubit>(
create: (context) =>
ConnectionStateCubit(ProcessorRepository.instance)),
BlocProvider<RouterCubit>(
create: (context) =>
RouterCubit(AccountRepository.instance),

View File

@ -19,11 +19,11 @@ Future<void> initializeVeilid() async {
// Veilid logging
initVeilidLog(kDebugMode);
// DHT Record Pool
await DHTRecordPool.init();
// Startup Veilid
await ProcessorRepository.instance.startup();
// DHT Record Pool
await DHTRecordPool.init();
}
// Initialize repositories

View File

@ -1,33 +1,60 @@
import 'package:bloc/bloc.dart';
import 'package:loggy/loggy.dart';
import 'loggy.dart';
const Map<String, LogLevel> _blocChangeLogLevels = {
'ConnectionStateCubit': LogLevel.off
};
const Map<String, LogLevel> _blocCreateCloseLogLevels = {};
const Map<String, LogLevel> _blocErrorLogLevels = {};
/// [BlocObserver] for the VeilidChat application that
/// observes all state changes.
class StateLogger extends BlocObserver {
/// {@macro counter_observer}
const StateLogger();
void _checkLogLevel(
Map<String, LogLevel> blocLogLevels,
LogLevel defaultLogLevel,
BlocBase<dynamic> bloc,
void Function(LogLevel) closure) {
final logLevel =
blocLogLevels[bloc.runtimeType.toString()] ?? defaultLogLevel;
if (logLevel != LogLevel.off) {
closure(logLevel);
}
}
@override
void onChange(BlocBase<dynamic> bloc, Change<dynamic> change) {
super.onChange(bloc, change);
log.debug('Change: ${bloc.runtimeType} $change');
_checkLogLevel(_blocChangeLogLevels, LogLevel.debug, bloc, (logLevel) {
log.log(logLevel, 'Change: ${bloc.runtimeType} $change');
});
}
@override
void onCreate(BlocBase<dynamic> bloc) {
super.onCreate(bloc);
log.debug('Create: ${bloc.runtimeType}');
_checkLogLevel(_blocCreateCloseLogLevels, LogLevel.debug, bloc, (logLevel) {
log.log(logLevel, 'Create: ${bloc.runtimeType}');
});
}
@override
void onClose(BlocBase<dynamic> bloc) {
super.onClose(bloc);
log.debug('Close: ${bloc.runtimeType}');
_checkLogLevel(_blocCreateCloseLogLevels, LogLevel.debug, bloc, (logLevel) {
log.log(logLevel, 'Close: ${bloc.runtimeType}');
});
}
@override
void onError(BlocBase<dynamic> bloc, Object error, StackTrace stackTrace) {
super.onError(bloc, error, stackTrace);
log.error('Error: ${bloc.runtimeType} $error\n$stackTrace');
_checkLogLevel(_blocErrorLogLevels, LogLevel.error, bloc, (logLevel) {
log.log(logLevel, 'Error: ${bloc.runtimeType} $error\n$stackTrace');
});
}
}