mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-12-25 23:59:32 -05:00
66 lines
2.0 KiB
Dart
66 lines
2.0 KiB
Dart
import 'package:bloc/bloc.dart';
|
|
import 'package:loggy/loggy.dart';
|
|
import 'loggy.dart';
|
|
|
|
const Map<String, LogLevel> _blocChangeLogLevels = {
|
|
'ConnectionStateCubit': LogLevel.off,
|
|
'ActiveSingleContactChatBlocMapCubit': LogLevel.off,
|
|
'ActiveConversationsBlocMapCubit': LogLevel.off,
|
|
'DHTShortArrayCubit<Message>': LogLevel.off,
|
|
'PersistentQueueCubit<Message>': LogLevel.off,
|
|
'SingleContactMessagesCubit': 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);
|
|
_checkLogLevel(_blocChangeLogLevels, LogLevel.debug, bloc, (logLevel) {
|
|
log.log(logLevel, 'Change: ${bloc.runtimeType} $change');
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onCreate(BlocBase<dynamic> bloc) {
|
|
super.onCreate(bloc);
|
|
_checkLogLevel(_blocCreateCloseLogLevels, LogLevel.debug, bloc, (logLevel) {
|
|
log.log(logLevel, 'Create: ${bloc.runtimeType}');
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onClose(BlocBase<dynamic> bloc) {
|
|
super.onClose(bloc);
|
|
_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);
|
|
_checkLogLevel(_blocErrorLogLevels, LogLevel.error, bloc, (logLevel) {
|
|
log.log(logLevel, 'Error: ${bloc.runtimeType} $error\n$stackTrace');
|
|
});
|
|
}
|
|
}
|