Skip to main content

structured_log_bloc 0.1.0-dev.8 copy "structured_log_bloc: ^0.1.0-dev.8" to clipboard
structured_log_bloc: ^0.1.0-dev.8 copied to clipboard

StructuredLogBlocObserver — a BlocObserver that turns the lifecycle, events, state changes and errors of every bloc and cubit into structured_log entries. Works with flutter_bloc as is.

example/main.dart

import 'package:bloc/bloc.dart';
import 'package:structured_log/structured_log.dart';
import 'package:structured_log_bloc/structured_log_bloc.dart';

sealed class CounterEvent {}

class Incremented extends CounterEvent {
  @override
  String toString() => 'Incremented()';
}

class CounterBloc extends Bloc<CounterEvent, int> {
  CounterBloc() : super(0) {
    on<Incremented>((event, emit) => emit(state + 1));
  }
}

class ThemeCubit extends Cubit<String> {
  ThemeCubit() : super('light');

  void toggle() => emit(state == 'light' ? 'dark' : 'light');
}

Future<void> main() async {
  StructlogConfiguration.configure(
    sinks: [LogSink(name: 'console', output: coloredConsoleOutput)],
  );
  Bloc.observer = StructuredLogBlocObserver();

  final counter = CounterBloc()..add(Incremented());
  final theme = ThemeCubit()..toggle();

  await counter.stream.first;
  await counter.close();
  await theme.close();
}
0
likes
130
points
796
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

StructuredLogBlocObserver — a BlocObserver that turns the lifecycle, events, state changes and errors of every bloc and cubit into structured_log entries. Works with flutter_bloc as is.

Homepage
Repository (GitHub)
View/report issues

Topics

#logging #bloc #state-management #structured-logging #debugging

License

MIT (license)

Dependencies

bloc, structured_log

More

Packages that depend on structured_log_bloc