Skip to content

Commit

Permalink
Merge pull request #90 from Frezyx/dev
Browse files Browse the repository at this point in the history
Release talker_bloc_logger package
  • Loading branch information
Frezyx authored Dec 31, 2022
2 parents 8fcf5e9 + 88539bf commit e8776ea
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 5 deletions.
Binary file added docs/assets/talker_bloc_logger/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/talker_bloc_logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions packages/talker_bloc_logger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

Initial release with base **TalkerBlocObserver** implementation
21 changes: 21 additions & 0 deletions packages/talker_bloc_logger/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Stanislav Ilin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions packages/talker_bloc_logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# talker_bloc_logger
Lightweight and customizable [BLoC](https://pub.dev/packages/bloc) state management library logger on [talker](https://pub.dev/packages/talker) base.<br>
[Talker](https://github.com/Frezyx/talker) - Advanced exception handling and logging for dart/flutter applications 🚀

<p>
<a href="https://github.com/Frezyx/talker"><img src="https://img.shields.io/github/stars/Frezyx/talker?style=social" alt="GitHub"></a>
<a href="https://codecov.io/gh/Frezyx/talker"><img src="https://codecov.io/gh/Frezyx/talker/branch/master/graph/badge.svg" alt="codecov"></a>
<a href="https://pub.dev/packages/talker_bloc_logger"><img src="https://img.shields.io/pub/v/talker_bloc_logger.svg" alt="Pub"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
<br>
<a href="https://github.com/Frezyx/talker/actions"><img src="https://github.com/Frezyx/talker/workflows/talker/badge.svg" alt="talker"></a>
<a href="https://github.com/Frezyx/talker_flutter/actions"><img src="https://github.com/Frezyx/talker/workflows/talker_flutter/badge.svg" alt="talker_flutter"></a>
<a href="https://github.com/Frezyx/talker_logger/actions"><img src="https://github.com/Frezyx/talker/workflows/talker_logger/badge.svg" alt="talker_logger"></a>
</p>

## Preview
This is how the logs of your BLoC's event callign and state emits will look in the console
![](https://github.com/Frezyx/talker/blob/dev/docs/assets/talker_bloc_logger/preview.png?raw=true)

## Getting started
Follow these steps to use this package

### Add dependency
```yaml
dependencies:
talker_bloc_logger: ^0.1.0
```
### Usage
Just set **TalkerBlocObserver** as Bloc.observer field and it will work
```dart
import 'package:talker_bloc_observer/talker_bloc_observer.dart';

Bloc.observer = TalkerBlocObserver();
```

## Using with Talker
You can add your talker instance for TalkerDioLogger if your app already uses Talker.

In this case, all logs and errors will fall into your unified tracking system

```dart
import 'package:talker_bloc_observer/talker_bloc_observer.dart';
import 'package:talker/talker.dart';
final talker = Talker();
Bloc.observer = TalkerBlocObserver(talker: talker);
```

## Additional information
The project is under development and ready for your pull-requests and issues 👍<br>
Thank you for support ❤️

30 changes: 30 additions & 0 deletions packages/talker_bloc_logger/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:bloc/bloc.dart';
import 'package:talker_bloc_logger/talker_bloc_logger.dart';

void main() async {
Bloc.observer = TalkerBlocObserver();
final somethingBloc = SomethingBloc();
somethingBloc.add(LoadSomething(LoadSomethingCase.successful));
await Future.delayed(const Duration(milliseconds: 300));
somethingBloc.add(LoadSomething(LoadSomethingCase.failure));
}

enum LoadSomethingCase { successful, failure }

class SomethingBloc extends Bloc<SomethingEvent, SomethingState> {
SomethingBloc() : super(SomethingInitial()) {
on<LoadSomething>((event, emit) {
emit(SomethingLoading());
if (event.loadCase == LoadSomethingCase.successful) {
emit(SomethingLoaded());
return;
}
throw Exception('Load something failure');
});
}
}

abstract class SomethingEvent {}

class LoadSomething extends SomethingEvent {
LoadSomething(this.loadCase);

final LoadSomethingCase loadCase;
}

abstract class SomethingState {}

class SomethingInitial extends SomethingState {}

class SomethingLoading extends SomethingState {}

class SomethingLoaded extends SomethingState {}

class SomethingLoadingFailure extends SomethingState {
SomethingLoadingFailure(this.exception);
final Object? exception;
}
38 changes: 38 additions & 0 deletions packages/talker_bloc_logger/lib/bloc_logs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:bloc/bloc.dart';
import 'package:talker/talker.dart';

/// [Bloc] event log model
class BlocEventLog extends TalkerLog {
BlocEventLog(Bloc bloc, Object? event) : super(_createMessage(bloc, event));

@override
AnsiPen get pen => AnsiPen()..xterm(51);

@override
String get title => 'BLOC';

static String _createMessage(Bloc bloc, Object? event) {
return 'Event recive in ${bloc.runtimeType} event: ${event.runtimeType}';
}
}

/// [Bloc] state log model
class BlocStateLog extends TalkerLog {
BlocStateLog(Bloc bloc, Transition transition)
: super(_createMessage(bloc, transition));

@override
AnsiPen get pen => AnsiPen()..xterm(49);

@override
String get title => 'BLOC';

static String _createMessage(Bloc bloc, Transition transition) {
final sb = StringBuffer();
sb.write(
'\n${'TRANSITION in ${bloc.runtimeType} with event ${transition.event.runtimeType}'}');
sb.write('\n${'CURRENT state: ${transition.currentState.runtimeType}'}');
sb.write('\n${'NEXT state: ${transition.nextState.runtimeType}'}');
return sb.toString();
}
}
3 changes: 3 additions & 0 deletions packages/talker_bloc_logger/lib/talker_bloc_logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library talker_bloc_logger;

export 'talker_bloc_logger_observer.dart';
40 changes: 40 additions & 0 deletions packages/talker_bloc_logger/lib/talker_bloc_logger_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
import 'package:talker/talker.dart';
import 'package:talker_bloc_logger/bloc_logs.dart';

/// [BLoC] logger on [Talker] base
///
/// [talker] filed is current [Talker] instance.
/// Provide your instance if your application used [Talker] as default logger
/// Commont Talker instance will be used by default
class TalkerBlocObserver extends BlocObserver {
TalkerBlocObserver({
Talker? talker,
}) {
_talker = talker ?? Talker();
}

late TalkerInterface _talker;

@override
@mustCallSuper
void onEvent(Bloc bloc, Object? event) {
super.onEvent(bloc, event);
_talker.logTyped(BlocEventLog(bloc, event));
}

@override
@mustCallSuper
void onTransition(Bloc bloc, Transition transition) {
super.onTransition(bloc, transition);
_talker.logTyped(BlocStateLog(bloc, transition));
}

@override
@mustCallSuper
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
super.onError(bloc, error, stackTrace);
_talker.error('${bloc.runtimeType}', error, stackTrace);
}
}
18 changes: 18 additions & 0 deletions packages/talker_bloc_logger/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: talker_bloc_logger
description: Lightweight and customizable BLoC state management library logger on talker base.
version: 0.1.0
homepage: https://github.com/Frezyx/talker
repository: https://github.com/Frezyx/talker
issue_tracker: https://github.com/Frezyx/talker/issues

environment:
sdk: '>=2.15.0 <3.0.0'

dependencies:
talker: ^2.2.1
bloc: ^8.1.0
meta: ^1.8.0

dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
6 changes: 3 additions & 3 deletions packages/talker_dio_logger/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ packages:
name: talker
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.2.1"
talker_dio_logger:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.0.2"
talker_flutter:
dependency: "direct main"
description:
Expand All @@ -314,7 +314,7 @@ packages:
name: talker_logger
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.2.1"
term_glyph:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TalkerDioLogger extends Interceptor {
_talker = talker ??
Talker(
settings: TalkerSettings(),
//TODO: fix
loggerSettings: TalkerLoggerSettings(
enableColors: !Platform.isIOS && !Platform.isMacOS,
),
Expand Down
2 changes: 1 addition & 1 deletion packages/talker_dio_logger/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:

dependencies:
dio: ^4.0.6
talker: ^2.1.0
talker: ^2.2.0

dev_dependencies:
lint: ^2.0.1
Expand Down
2 changes: 1 addition & 1 deletion packages/talker_flutter/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.11/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.20/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":false,"dependencies":["url_launcher_linux"]},{"name":"url_launcher_linux","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-3.0.1/","native_build":true,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.3/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":["url_launcher_windows"]},{"name":"url_launcher_windows","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-3.0.1/","native_build":true,"dependencies":[]}],"web":[{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","dependencies":["url_launcher_web"]},{"name":"url_launcher_web","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.13/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"share_plus","dependencies":["url_launcher_web","url_launcher_windows","url_launcher_linux"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-12-31 17:09:11.167343","version":"3.3.10"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.11/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.20/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":false,"dependencies":["url_launcher_linux"]},{"name":"url_launcher_linux","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-3.0.1/","native_build":true,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.3/","native_build":false,"dependencies":[]},{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","native_build":true,"dependencies":["url_launcher_windows"]},{"name":"url_launcher_windows","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-3.0.1/","native_build":true,"dependencies":[]}],"web":[{"name":"share_plus","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/share_plus-6.3.0/","dependencies":["url_launcher_web"]},{"name":"url_launcher_web","path":"/Users/stanislavilin/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.13/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"share_plus","dependencies":["url_launcher_web","url_launcher_windows","url_launcher_linux"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-12-31 17:14:47.533131","version":"3.3.10"}
2 changes: 2 additions & 0 deletions packages/talker_logger/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: talker_logger
description: Logger core package for talker (advanced error handler and logger package)
version: 2.2.1
homepage: https://github.com/Frezyx/talker
repository: https://github.com/Frezyx/talker
issue_tracker: https://github.com/Frezyx/talker/issues

environment:
sdk: '>=2.15.0 <3.0.0'
Expand Down

0 comments on commit e8776ea

Please sign in to comment.