diff --git a/README.md b/README.md index fd60faf7..fc96c0c5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Follow these steps to use this package ### Add dependency ```yaml dependencies: - talker: ^0.6.0 + talker: ^0.7.0 ``` ### Easy to use @@ -86,8 +86,8 @@ Often you need to check what happening in the application when there is no conso ### Add dependency ```yaml dependencies: - talker: ^0.6.0 - talker_flutter: ^0.5.0 + talker: ^0.7.0 + talker_flutter: ^0.5.3 ``` ### Easy to use @@ -104,6 +104,8 @@ TalkerScreen(talker: Talker.instance) - ErrorLevel as a model with customization - Filter for logs in UI (talker_flutter) - Flutter Talker customization / filters +- TalkerLogger settings using by Talker +- Remove additional field in TalkerDataInterface and all extended models For help getting started with 😍 Flutter, view [online documentation](https://flutter.dev/docs), which offers tutorials, diff --git a/talker/CHANGELOG.md b/talker/CHANGELOG.md index 9a076008..5d1ec1b7 100644 --- a/talker/CHANGELOG.md +++ b/talker/CHANGELOG.md @@ -1,3 +1,13 @@ +## 0.7.0 +- **BREAKING** Remove talker_error_handler package from talker deps +- **BREAKING** Rewrite error handler on talker package base +- **BREAKING** Update handle error / exceptions methods + +## 0.6.1 +- **BREAKING** Remove TalkerDataInterface, +TalkerLog, TalkerError, TalkerException field additional data + + ## 0.6.0 - Implement filter for logs diff --git a/talker/README.md b/talker/README.md index fd60faf7..323b96af 100644 --- a/talker/README.md +++ b/talker/README.md @@ -37,7 +37,7 @@ Follow these steps to use this package ### Add dependency ```yaml dependencies: - talker: ^0.6.0 + talker: ^0.7.0 ``` ### Easy to use @@ -86,8 +86,8 @@ Often you need to check what happening in the application when there is no conso ### Add dependency ```yaml dependencies: - talker: ^0.6.0 - talker_flutter: ^0.5.0 + talker: ^0.7.0 + talker_flutter: ^0.5.3 ``` ### Easy to use diff --git a/talker/example/talker_example.dart b/talker/example/talker_example.dart index c5c39249..caab981f 100644 --- a/talker/example/talker_example.dart +++ b/talker/example/talker_example.dart @@ -22,22 +22,18 @@ Future main() async { try { throw Exception('Test service exception'); } catch (e, st) { - Talker.instance.handle(e, 'Working with string error', st); + Talker.instance.handle(e, st, 'Working with string error'); } try { throw Exception('Service can`t get test data'); } on Exception catch (e, st) { - Talker.instance.handleException(e, 'Working with strings exception', st); + Talker.instance.handleException(e, st, 'Working with strings exception'); } Talker.instance.log( 'Server error', logLevel: LogLevel.critical, - additional: { - "status": 500, - "error": "Internal Server Error", - }, ); Talker.instance.fine('Log fine'); diff --git a/talker/lib/src/extensions/extensions.dart b/talker/lib/src/extensions/extensions.dart index c2a7f451..e89edcc4 100644 --- a/talker/lib/src/extensions/extensions.dart +++ b/talker/lib/src/extensions/extensions.dart @@ -1,2 +1 @@ -export 'log_level.dart'; export 'talker_data.dart'; diff --git a/talker/lib/src/extensions/log_level.dart b/talker/lib/src/extensions/log_level.dart deleted file mode 100644 index 5e3eea10..00000000 --- a/talker/lib/src/extensions/log_level.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:talker/talker.dart'; - -extension ToLogLevel on ErrorLevel? { - /// Converted [ErrorLevel] in [LogLevel] - LogLevel get loglevel { - switch (this) { - case ErrorLevel.critical: - return LogLevel.critical; - case ErrorLevel.info: - return LogLevel.info; - case ErrorLevel.tiny: - return LogLevel.verbose; - case ErrorLevel.warning: - return LogLevel.warning; - case ErrorLevel.debug: - case null: - return LogLevel.error; - } - } -} diff --git a/talker/lib/src/models/talker_data/talker_data_interface.dart b/talker/lib/src/models/talker_data/talker_data_interface.dart index dc27f27d..1a4ff324 100644 --- a/talker/lib/src/models/talker_data/talker_data_interface.dart +++ b/talker/lib/src/models/talker_data/talker_data_interface.dart @@ -34,11 +34,6 @@ abstract class TalkerDataInterface { /// {@endtemplate} StackTrace? get stackTrace; - /// {@template talker_data_additional} - /// [Map?] [additional] - additional log data for - /// {@endtemplate} - Map? get additional; - /// {@template talker_data_time} /// Internal time when the error occurred /// {@endtemplate} @@ -106,14 +101,6 @@ extension FeildsToDisplay on TalkerDataInterface { return '\n$error'; } - /// Displayed additional of [TalkerDataInterface] - String get displayAditional { - if (additional == null) { - return ''; - } - return '\n$additional'; - } - /// Displayed message of [TalkerDataInterface] String get displayMessage { if (message == null) { diff --git a/talker/lib/src/models/talker_data/talker_error.dart b/talker/lib/src/models/talker_data/talker_error.dart index 7679cade..f7cc1ea2 100644 --- a/talker/lib/src/models/talker_data/talker_error.dart +++ b/talker/lib/src/models/talker_data/talker_error.dart @@ -46,13 +46,24 @@ class TalkerError implements TalkerDataInterface { @override DateTime get time => _time; - /// {@macro talker_data_additional} - /// Not used in [TalkerError] - @override - final Map? additional = null; - /// {@macro talker_data_exception} /// Not used in [TalkerError] @override final Exception? exception = null; + + TalkerError copyWith({ + Error? error, + String? message, + StackTrace? stackTrace, + String? title, + LogLevel? logLevel, + }) { + return TalkerError( + error ?? this.error, + message: message ?? this.message, + stackTrace: stackTrace ?? this.stackTrace, + title: title ?? this.title, + logLevel: logLevel ?? this.logLevel, + ); + } } diff --git a/talker/lib/src/models/talker_data/talker_exception.dart b/talker/lib/src/models/talker_data/talker_exception.dart index 29a6cc24..8a90da17 100644 --- a/talker/lib/src/models/talker_data/talker_exception.dart +++ b/talker/lib/src/models/talker_data/talker_exception.dart @@ -50,9 +50,4 @@ class TalkerException implements TalkerDataInterface { /// Not used in [TalkerException] @override final Error? error = null; - - /// {@macro talker_data_additional} - /// Not used in [TalkerException] - @override - final Map? additional = null; } diff --git a/talker/lib/src/models/talker_data/talker_log.dart b/talker/lib/src/models/talker_data/talker_log.dart index 77135bc9..d6e3c2d1 100644 --- a/talker/lib/src/models/talker_data/talker_log.dart +++ b/talker/lib/src/models/talker_data/talker_log.dart @@ -9,7 +9,6 @@ class TalkerLog implements TalkerDataInterface { this.exception, this.error, this.stackTrace, - this.additional, this.title, DateTime? time, this.pen, @@ -38,10 +37,6 @@ class TalkerLog implements TalkerDataInterface { @override final String? title; - /// {@macro talker_data_additional} - @override - final Map? additional; - /// {@macro talker_data_loglevel} @override final LogLevel? logLevel; @@ -49,7 +44,7 @@ class TalkerLog implements TalkerDataInterface { /// {@macro talker_data_generateTextMessage} @override String generateTextMessage() { - return '$displayTitleWithTime$message$displayAditional'; + return '$displayTitleWithTime$message'; } /// {@macro talker_data_time} diff --git a/talker/lib/src/observers/observers_manager.dart b/talker/lib/src/observers/observers_manager.dart index cd29a073..0a46f00d 100644 --- a/talker/lib/src/observers/observers_manager.dart +++ b/talker/lib/src/observers/observers_manager.dart @@ -1,23 +1,29 @@ import 'package:talker/src/models/talker_data/talker_data.dart'; import 'package:talker/src/observers/talker_observer.dart'; -import 'package:talker_error_handler/talker_error_handler.dart'; /// Manager to wrap all observers class TalkerObserversManager { TalkerObserversManager(this.observers); final List observers; - /// Called when [Talker] handle an error / exception - void onError(ErrorDetails container) { + /// Called when [Talker] handle an [TalkerError] + void onError(TalkerError talkerError) { for (final o in observers) { - o.onError?.call(container); + o.onError?.call(talkerError); } } - /// Called when [Talker] handle an log - void onLog(TalkerDataInterface data) { + /// Called when [Talker] handle an [TalkerException] + void onException(TalkerException talkerException) { for (final o in observers) { - o.onLog?.call(data); + o.onException?.call(talkerException); + } + } + + /// Called when [Talker] handle an [TalkerDataInterface] log + void onLog(TalkerDataInterface log) { + for (final o in observers) { + o.onLog?.call(log); } } } diff --git a/talker/lib/src/observers/talker_observer.dart b/talker/lib/src/observers/talker_observer.dart index 80b2ac36..58e7e9a1 100644 --- a/talker/lib/src/observers/talker_observer.dart +++ b/talker/lib/src/observers/talker_observer.dart @@ -1,5 +1,4 @@ import 'package:talker/src/models/talker_data/talker_data.dart'; -import 'package:talker_error_handler/talker_error_handler.dart'; /// Base observer class for /// to create your own observers @@ -7,11 +6,15 @@ class TalkerObserver { const TalkerObserver({ this.onError, this.onLog, + this.onException, }); - /// Called when [Talker] handle an error / exception - final Function(ErrorDetails err)? onError; + /// Called when [Talker] handle an [TalkerError] + final Function(TalkerError err)? onError; - /// Called when [Talker] handle an log - final Function(TalkerDataInterface data)? onLog; + /// Called when [Talker] handle an [TalkerException] + final Function(TalkerException err)? onException; + + /// Called when [Talker] handle an [TalkerDataInterface] log + final Function(TalkerDataInterface log)? onLog; } diff --git a/talker/lib/src/talker.dart b/talker/lib/src/talker.dart index 4575ebea..8e2010f3 100644 --- a/talker/lib/src/talker.dart +++ b/talker/lib/src/talker.dart @@ -6,10 +6,7 @@ class Talker implements TalkerInterface { Talker._() { _settings = kDefaultTalkerSettings; _logger = TalkerLogger(); - _errorHandler = ErrorHandler() - ..stream.listen((details) { - _handleErrorStream(details); - }); + _errorHandler = TalkerErrorHandler(_settings); } static final _talker = Talker._(); @@ -17,8 +14,8 @@ class Talker implements TalkerInterface { /// Fields can be setup in [configure()] method late TalkerSettings _settings; - late TalkerLogger _logger; - late ErrorHandler _errorHandler; + late TalkerLoggerInterface _logger; + late TalkerErrorHandlerInterface _errorHandler; // final _fileManager = FileManager(); final _history = []; @@ -28,7 +25,6 @@ class Talker implements TalkerInterface { @override Future configure({ TalkerLogger? logger, - ErrorHandler? errorHandler, TalkerSettings? settings, List? observers, }) async { @@ -43,13 +39,6 @@ class Talker implements TalkerInterface { if (logger != null) { _logger = logger; } - - if (errorHandler != null) { - _errorHandler = errorHandler - ..stream.listen((details) { - _handleErrorStream(details); - }); - } } final _talkerStreamController = @@ -68,18 +57,23 @@ class Talker implements TalkerInterface { @override void handle( Object exception, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]) { - final details = _errorHandler.handle( - exception, - msg, - stackTrace, - errorLevel, - ); - if (details != null) { - _observersManager?.onError(details); + final data = _errorHandler.handle(exception, stackTrace, msg); + if (data is TalkerError) { + _observersManager?.onError(data); + _handleErrorData(data); + return; + } + if (data is TalkerException) { + _observersManager?.onException(data); + _handleErrorData(data); + return; + } + if (data is TalkerLog) { + _handleLogData(data); } } @@ -87,26 +81,36 @@ class Talker implements TalkerInterface { @override void handleError( Error error, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]) { - final errContainer = - _errorHandler.handleError(error, msg, stackTrace, errorLevel); - _observersManager?.onError(errContainer); + final data = TalkerError( + error, + stackTrace: stackTrace, + message: msg, + logLevel: LogLevel.error, + ); + _handleErrorData(data); + _observersManager?.onError(data); } /// {@macro talker_handleException} @override void handleException( Exception exception, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]) { - final errContainer = - _errorHandler.handleException(exception, msg, stackTrace, errorLevel); - _observersManager?.onError(errContainer); + final data = TalkerException( + exception, + stackTrace: stackTrace, + message: msg, + logLevel: LogLevel.error, + ); + _handleErrorData(data); + _observersManager?.onException(data); } /// {@macro talker_log} @@ -114,19 +118,11 @@ class Talker implements TalkerInterface { void log( String message, { LogLevel logLevel = LogLevel.debug, - Map? additional, Object? exception, StackTrace? stackTrace, AnsiPen? pen, }) { - _handleLog( - exception, - message, - stackTrace, - logLevel, - additional: additional, - pen: pen, - ); + _handleLog(message, exception, stackTrace, logLevel, pen: pen); } /// {@macro talker_log_typed} @@ -142,7 +138,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.critical); + _handleLog(msg, exception, stackTrace, LogLevel.critical); } /// {@macro talker_debug_log} @@ -152,7 +148,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.debug); + _handleLog(msg, exception, stackTrace, LogLevel.debug); } /// {@macro talker_error_log} @@ -162,7 +158,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.error); + _handleLog(msg, exception, stackTrace, LogLevel.error); } /// {@macro talker_fine_log} @@ -172,7 +168,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.fine); + _handleLog(msg, exception, stackTrace, LogLevel.fine); } /// {@macro talker_good_log} @@ -182,7 +178,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.good); + _handleLog(msg, exception, stackTrace, LogLevel.good); } /// {@macro talker_info_log} @@ -192,7 +188,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.info); + _handleLog(msg, exception, stackTrace, LogLevel.info); } /// {@macro talker_verbose_log} @@ -202,7 +198,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.verbose); + _handleLog(msg, exception, stackTrace, LogLevel.verbose); } /// {@macro talker_warning_log} @@ -212,7 +208,7 @@ class Talker implements TalkerInterface { Object? exception, StackTrace? stackTrace, ]) { - _handleLog(exception, msg, stackTrace, LogLevel.warning); + _handleLog(msg, exception, stackTrace, LogLevel.warning); } ///{@macro talker_clear_log_history} @@ -224,36 +220,52 @@ class Talker implements TalkerInterface { } void _handleLog( - Object? exception, String message, + Object? exception, StackTrace? stackTrace, LogLevel logLevel, { - Map? additional, AnsiPen? pen, }) { TalkerDataInterface? data; if (exception != null) { - handle(exception, message, stackTrace); + handle(exception, stackTrace, message); return; } - data = TalkerLog( - message, - logLevel: logLevel, - additional: additional, - ); - + data = TalkerLog(message, logLevel: logLevel); _handleLogData(data as TalkerLog, pen: pen); } + void _handleErrorData(TalkerDataInterface data) { + _talkerStreamController.add(data); + _handleForOutputs(data); + if (_settings.useConsoleLogs) { + _logger.log( + data.generateTextMessage(), + level: data.logLevel ?? LogLevel.error, + ); + } + } + void _handleLogData( TalkerLog data, { AnsiPen? pen, LogLevel? logLevel, }) { - _talkerStreamController.add(data); _observersManager?.onLog(data); + + // if (data.error != null) { + // handleError(data.error!); + // return; + // } + + // if (data.exception != null) { + // handleException(data.exception!); + // return; + // } + + _talkerStreamController.add(data); _handleForOutputs(data); if (_settings.useConsoleLogs) { _logger.log( @@ -265,9 +277,8 @@ class Talker implements TalkerInterface { } void _handleForOutputs(TalkerDataInterface data) { - if (_settings.useHistory) { - _writeToHistory(data); - } + _writeToHistory(data); + // _writeToFile(data); } @@ -286,36 +297,4 @@ class Talker implements TalkerInterface { _history.add(data); } } - - void _handleErrorStream(ErrorDetails details) { - TalkerDataInterface? data; - final err = details.error; - final exception = details.exception; - if (err != null) { - data = TalkerError( - err, - message: details.message, - stackTrace: details.stackTrace, - logLevel: details.errorLevel?.loglevel ?? LogLevel.error, - ); - } else if (exception != null) { - data = TalkerException( - exception, - message: details.message, - stackTrace: details.stackTrace, - logLevel: details.errorLevel?.loglevel ?? LogLevel.error, - ); - } - - if (data != null) { - _talkerStreamController.add(data); - _handleForOutputs(data); - if (_settings.useConsoleLogs) { - _logger.log( - data.generateTextMessage(), - level: data.logLevel ?? LogLevel.error, - ); - } - } - } } diff --git a/talker/lib/src/talker_interface.dart b/talker/lib/src/talker_interface.dart index c2939e2a..ea6b7795 100644 --- a/talker/lib/src/talker_interface.dart +++ b/talker/lib/src/talker_interface.dart @@ -55,9 +55,9 @@ abstract class TalkerInterface { /// {@endtemplate} void handle( Object exception, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]); /// {@template talker_handleError} @@ -76,9 +76,9 @@ abstract class TalkerInterface { /// {@endtemplate} void handleError( Error error, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]); /// {@template talker_handleError} @@ -97,9 +97,9 @@ abstract class TalkerInterface { /// {@endtemplate} void handleException( Exception exception, [ - String? msg, StackTrace? stackTrace, - ErrorLevel? errorLevel, + String? msg, + // ErrorLevel? errorLevel, ]); /// {@template talker_log} @@ -128,7 +128,6 @@ abstract class TalkerInterface { void log( String message, { LogLevel logLevel = LogLevel.debug, - Map? additional, Object? exception, StackTrace? stackTrace, AnsiPen? pen, diff --git a/talker/lib/src/utils/error_handler/error_handler.dart b/talker/lib/src/utils/error_handler/error_handler.dart new file mode 100644 index 00000000..d334a455 --- /dev/null +++ b/talker/lib/src/utils/error_handler/error_handler.dart @@ -0,0 +1,2 @@ +export 'talker_error_handler.dart'; +export 'talker_error_handler_interface.dart'; diff --git a/talker/lib/src/utils/error_handler/talker_error_handler.dart b/talker/lib/src/utils/error_handler/talker_error_handler.dart new file mode 100644 index 00000000..886d3c83 --- /dev/null +++ b/talker/lib/src/utils/error_handler/talker_error_handler.dart @@ -0,0 +1,35 @@ +import 'package:talker/talker.dart'; + +class TalkerErrorHandler implements TalkerErrorHandlerInterface { + TalkerErrorHandler(this.settings); + + final TalkerSettings settings; + + @override + TalkerDataInterface handle( + Object exception, [ + StackTrace? stackTrace, + String? msg, + ]) { + if (exception is Error) { + return TalkerError( + exception, + stackTrace: stackTrace, + message: msg, + logLevel: LogLevel.error, + ); + } else if (exception is Exception) { + return TalkerException( + exception, + stackTrace: stackTrace, + message: msg, + logLevel: LogLevel.error, + ); + } + return TalkerLog( + exception.toString(), + logLevel: LogLevel.error, + stackTrace: stackTrace, + ); + } +} diff --git a/talker/lib/src/utils/error_handler/talker_error_handler_interface.dart b/talker/lib/src/utils/error_handler/talker_error_handler_interface.dart new file mode 100644 index 00000000..435b838e --- /dev/null +++ b/talker/lib/src/utils/error_handler/talker_error_handler_interface.dart @@ -0,0 +1,9 @@ +import 'package:talker/talker.dart'; + +abstract class TalkerErrorHandlerInterface { + TalkerDataInterface handle( + Object exception, [ + StackTrace? stackTrace, + String? msg, + ]); +} diff --git a/talker/lib/src/utils/utils.dart b/talker/lib/src/utils/utils.dart index 3bbe8570..4762bc3f 100644 --- a/talker/lib/src/utils/utils.dart +++ b/talker/lib/src/utils/utils.dart @@ -1,2 +1,3 @@ +export 'error_handler/error_handler.dart'; export 'file_manager/file_manager.dart'; export 'formaters/formaters.dart'; diff --git a/talker/lib/talker.dart b/talker/lib/talker.dart index bc08c331..30b5ac4f 100644 --- a/talker/lib/talker.dart +++ b/talker/lib/talker.dart @@ -1,6 +1,6 @@ library talker; -export 'package:talker_error_handler/talker_error_handler.dart'; +// export 'package:talker_error_handler/talker_error_handler.dart'; export 'package:talker_logger/talker_logger.dart'; export 'src/src.dart'; diff --git a/talker/pubspec.yaml b/talker/pubspec.yaml index 417f4e52..df22a660 100644 --- a/talker/pubspec.yaml +++ b/talker/pubspec.yaml @@ -1,6 +1,6 @@ name: talker description: Advanced error handler and logger package for flutter and dart apps -version: 0.6.0 +version: 0.7.0 homepage: https://github.com/Frezyx/talker environment: @@ -8,7 +8,7 @@ environment: dependencies: intl: ^0.17.0 - talker_error_handler: ^0.5.0 + # talker_error_handler: ^0.5.0 # path: # ../talker_error_handler # git: diff --git a/talker/test/talker_error_handler_test.dart b/talker/test/talker_error_handler_test.dart new file mode 100644 index 00000000..a124a6d9 --- /dev/null +++ b/talker/test/talker_error_handler_test.dart @@ -0,0 +1,57 @@ +import 'package:talker/talker.dart'; +import 'package:test/test.dart'; + +final _errHandler = TalkerErrorHandler(const TalkerSettings()); + +class TestException implements Exception {} + +class FakeTestException {} + +void main() { + group('Talker_ErrorHandler', () { + group('handle Error', () { + _testHandleError(ArgumentError()); + _testHandleError(NullThrownError()); + _testHandleError(AssertionError()); + }); + + group('handle Exception', () { + _testHandleException(Exception()); + _testHandleException(const FormatException()); + _testHandleException(TestException()); + }); + + group('handle something else', () { + _testHandleSomething(Object()); + _testHandleSomething('FFFFF'); + _testHandleSomething(FakeTestException()); + }); + }); +} + +void _testHandleError(Object err) { + test('$err', () { + final data = _errHandler.handle(err); + + expect(data, isNotNull); + expect(data, isA()); + }); +} + +void _testHandleException(Object exception) { + test('$exception', () { + final data = _errHandler.handle(exception); + + expect(data, isNotNull); + expect(data, isA()); + }); +} + +void _testHandleSomething(Object something) { + test('$something', () { + final data = _errHandler.handle(something); + + expect(data, isNotNull); + expect(data, isA()); + }); +} diff --git a/talker_error_handler/lib/src/error_handler.dart b/talker_error_handler/lib/src/error_handler.dart index 041775d7..e4c9c14c 100644 --- a/talker_error_handler/lib/src/error_handler.dart +++ b/talker_error_handler/lib/src/error_handler.dart @@ -45,6 +45,7 @@ class ErrorHandler implements ErrorHandlerInterface { return handleError(exception, msg, stackTrace, errorLevel); } else { onUnknownErrorType?.call(msg, exception, stackTrace, errorLevel); + return null; } } diff --git a/talker_flutter/CHANGELOG.md b/talker_flutter/CHANGELOG.md index 646a9cd0..4100a620 100644 --- a/talker_flutter/CHANGELOG.md +++ b/talker_flutter/CHANGELOG.md @@ -1,3 +1,13 @@ +## 0.5.3 +- Update talker version to 0.7.0 + +## 0.5.2 +- Fix display message parsing + +## 0.5.1 +- Update display message UI +- Update talker version to 0.6.1 + ## 0.5.0 - Implement UI filter for convenient work with the console in the application diff --git a/talker_flutter/example/android/build.gradle b/talker_flutter/example/android/build.gradle index 24047dce..4256f917 100644 --- a/talker_flutter/example/android/build.gradle +++ b/talker_flutter/example/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() diff --git a/talker_flutter/example/lib/main.dart b/talker_flutter/example/lib/main.dart index 3c208a81..8d9c9461 100644 --- a/talker_flutter/example/lib/main.dart +++ b/talker_flutter/example/lib/main.dart @@ -25,7 +25,7 @@ class _MyAppState extends State { _fineLog(); _infoLog(); _warningLog(); - _bigCriticalLog(); + _criticalLog(); _customLog(); super.initState(); } @@ -80,7 +80,7 @@ class _MyAppState extends State { ), BarButton( title: 'Big Critical log', - onTap: _bigCriticalLog, + onTap: _criticalLog, ), BarButton( title: 'Custom log', @@ -96,17 +96,11 @@ class _MyAppState extends State { } void _handleError() { - Talker.instance.handleError( - ArgumentError('-6 is not positive number'), - 'dart argument error', - ); + Talker.instance.handleError(ArgumentError('-6 is not positive number')); } void _handleException() { - Talker.instance.handleException( - Exception('Not connected'), - 'Http service is not working', - ); + Talker.instance.handleException(Exception('Not connected')); } void _fineLog() { @@ -137,20 +131,8 @@ class _MyAppState extends State { ); } - void _bigCriticalLog() { - Talker.instance.log( - 'Server exception', - logLevel: LogLevel.critical, - additional: { - "timestamp": 1510417124782, - "status": 500, - "error": "Internal Server Error", - "exception": "com.netflix.hystrix.exception.HystrixRuntimeException", - "message": - "ApplicationRepository#save(Application) failed and no fallback available.", - "path": "/application" - }, - ); + void _criticalLog() { + Talker.instance.log('Server exception', logLevel: LogLevel.critical); } } @@ -165,7 +147,7 @@ class CustomLog extends FlutterTalkerLog { @override String generateTextMessage() { - return pen.write(message); + return '| Custom leading | ' + message; } } diff --git a/talker_flutter/example/pubspec.lock b/talker_flutter/example/pubspec.lock index 78d95965..e4da29f4 100644 --- a/talker_flutter/example/pubspec.lock +++ b/talker_flutter/example/pubspec.lock @@ -109,6 +109,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: @@ -162,21 +169,14 @@ packages: name: talker url: "https://pub.dartlang.org" source: hosted - version: "0.6.0" - talker_error_handler: - dependency: transitive - description: - name: talker_error_handler - url: "https://pub.dartlang.org" - source: hosted - version: "0.5.0" + version: "0.7.0" talker_flutter: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.5.0" + version: "0.5.3" talker_logger: dependency: transitive description: @@ -197,7 +197,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.8" typed_data: dependency: transitive description: diff --git a/talker_flutter/lib/src/widgets/cards/talker_data_card.dart b/talker_flutter/lib/src/widgets/cards/talker_data_card.dart index 021ce31c..3614f666 100644 --- a/talker_flutter/lib/src/widgets/cards/talker_data_card.dart +++ b/talker_flutter/lib/src/widgets/cards/talker_data_card.dart @@ -45,7 +45,7 @@ class TalkerDataCard extends StatelessWidget { ), children: [ TextSpan( - text: data.displayMessage, + text: _message, style: const TextStyle( fontWeight: FontWeight.normal, ), @@ -88,24 +88,6 @@ class TalkerDataCard extends StatelessWidget { ], ), ), - if (data.additional != null) - RichText( - text: TextSpan( - text: 'Additional ', - style: TextStyle( - color: _color, - fontWeight: FontWeight.bold, - ), - children: [ - TextSpan( - text: data.displayAditional, - style: const TextStyle( - fontWeight: FontWeight.normal, - ), - ), - ], - ), - ), ], ), ), @@ -144,6 +126,26 @@ class TalkerDataCard extends StatelessWidget { ); } + // ignore: todo + //TODO: refactor + String get _message { + final message = data.generateTextMessage(); + final title = data.displayTitle; + final time = data.displayTime; + + var m = message; + + if (title.isNotEmpty && message.contains('[$title] ')) { + m = message.replaceAll('[$title] ', '').replaceFirst(' |', ''); + } + + if (time.isNotEmpty && m.contains(' $time ')) { + return m.replaceAll(' $time ', '').replaceFirst('|', ''); + } + + return m; + } + Color get _color { if (data is HaveFlutterColorInterface) { return (data as HaveFlutterColorInterface).color ?? data.logLevel.color; diff --git a/talker_flutter/pubspec.yaml b/talker_flutter/pubspec.yaml index e3dca2bb..bfff3664 100644 --- a/talker_flutter/pubspec.yaml +++ b/talker_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: talker_flutter description: Flutter implementation of talker (advanced error handler and logger package). -version: 0.5.0 +version: 0.5.3 homepage: https://github.com/Frezyx/talker environment: @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter - talker: ^0.6.0 + talker: ^0.7.0 # path: # ../talker # git: