Skip to content

Commit

Permalink
Merge pull request #6 from Frezyx/dev
Browse files Browse the repository at this point in the history
Release version 0.3.0
  • Loading branch information
Frezyx authored Jan 12, 2022
2 parents b5ccf90 + 81d584d commit 56b17b9
Show file tree
Hide file tree
Showing 39 changed files with 506 additions and 137 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
Advanced error catching and logging for dart/flutter applications

### 0.2.0
Working in progress
Working in progress

### TODO:
- LogLevel as a model with customization
- ErrorLevel as a model with customization
29 changes: 29 additions & 0 deletions talker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## 0.3.0
- Update settings cnfiguration
- Update internal logic
- Update internal packages

## 0.2.8
- Add useConsoleLogs settings field

## 0.2.7
- Update logger version

## 0.2.6
- Add AnsiPen customization for log method

## 0.2.5
- Update observer model

## 0.2.4
- Implement simple log methods

## 0.2.3
- Fix default (null) errorLevel -> logLevel

## 0.2.2
- Fix error_handler version

## 0.2.1
- Fix nested packages

## 0.2.0
- Simplified package api
- Fix Talker lazy configuration
Expand Down
6 changes: 6 additions & 0 deletions talker/example/talker_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ Future<void> main() async {
"path": "/application"
},
);

Talker.instance.fine('Log info');
Talker.instance.error('Log info');
Talker.instance.good('Log info');
Talker.instance.verbose('Log info');
Talker.instance.warning('Log info');
}
5 changes: 2 additions & 3 deletions talker/lib/src/extensions/log_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ extension ToLogLevel on ErrorLevel? {
switch (this) {
case ErrorLevel.critical:
return LogLevel.critical;
case ErrorLevel.debug:
return LogLevel.debug;
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.debug;
return LogLevel.error;
}
}
}
4 changes: 2 additions & 2 deletions talker/lib/src/models/talker_data/talker_data_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ extension GetTitle on TalkerDataInterface {
if (stackTrace == null) {
return '';
}
return '\nStackTrace:\n${stackTrace ?? ''}';
return '\n${stackTrace ?? ''}';
}

String get displayException {
if (exception == null) {
return '';
}
return '\nException: $exception';
return '\n$exception';
}

String get displayError {
Expand Down
4 changes: 2 additions & 2 deletions talker/lib/src/observers/observers_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class TalkerObserversManager {

void onError(ErrorDetails container) {
for (final o in observers) {
o.onError(container);
o.onError?.call(container);
}
}

void onLog(TalkerDataInterface data) {
for (final o in observers) {
o.onLog(data);
o.onLog?.call(data);
}
}
}
8 changes: 4 additions & 4 deletions talker/lib/src/observers/talker_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:talker_error_handler/talker_error_handler.dart';

class TalkerObserver {
const TalkerObserver({
required this.onError,
required this.onLog,
this.onError,
this.onLog,
});

final Function(ErrorDetails err) onError;
final Function(TalkerDataInterface data) onLog;
final Function(ErrorDetails err)? onError;
final Function(TalkerDataInterface data)? onLog;
}
2 changes: 2 additions & 0 deletions talker/lib/src/settings/talker_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const kDefaultTalkerSettings = TalkerSettings();
class TalkerSettings {
const TalkerSettings({
this.useHistory = true,
this.useConsoleLogs = true,
this.maxHistoryItems = 200,
this.writeToFile = false,
});

final bool useHistory;
final bool useConsoleLogs;
final int maxHistoryItems;
final bool writeToFile;
}
136 changes: 121 additions & 15 deletions talker/lib/src/talker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class Talker implements TalkerInterface {
}

static final _talker = Talker._();
static Talker get instance => _talker;
static TalkerInterface get instance => _talker;

/// Fields can be setup in [configure()] method
late TalkerSettings _settings;
late TalkerLogger _logger;
late ErrorHandler _errorHandler;
Expand Down Expand Up @@ -109,19 +108,122 @@ class Talker implements TalkerInterface {
String message, {
LogLevel logLevel = LogLevel.debug,
Map<String, dynamic>? additional,
Object? exception,
StackTrace? stackTrace,
AnsiPen? pen,
}) {
final logData = TalkerLog(
_handleLog(
exception,
message,
logLevel: logLevel,
stackTrace,
logLevel,
additional: additional,
pen: pen,
);
_talkerStreamController.add(logData);
_observersManager?.onLog(logData);
_handleForOutputs(logData);
_logger.log(
logData.generateTextMessage(),
level: logData.logLevel ?? LogLevel.debug,
}

@override
void critical(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.critical);
}

@override
void debug(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.debug);
}

@override
void error(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.error);
}

@override
void fine(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.fine);
}

@override
void good(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.good);
}

@override
void info(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.info);
}

@override
void verbose(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.verbose);
}

@override
void warning(
String msg, [
Object? exception,
StackTrace? stackTrace,
]) {
_handleLog(exception, msg, stackTrace, LogLevel.warning);
}

void _handleLog(
Object? exception,
String message,
StackTrace? stackTrace,
LogLevel logLevel, {
Map<String, dynamic>? additional,
AnsiPen? pen,
}) {
TalkerDataInterface? data;

if (exception != null) {
handle(exception, message, stackTrace);
return;
}

data = TalkerLog(
message,
logLevel: logLevel,
additional: additional,
);
_talkerStreamController.add(data);
_observersManager?.onLog(data);
_handleForOutputs(data);
if (_settings.useConsoleLogs) {
_logger.log(
data.generateTextMessage(),
level: data.logLevel,
pen: pen,
);
}
}

@override
Expand All @@ -132,7 +234,9 @@ class Talker implements TalkerInterface {
}

void _handleForOutputs(TalkerDataInterface data) {
_writeToHistory(data);
if (_settings.useHistory) {
_writeToHistory(data);
}
// _writeToFile(data);
}

Expand Down Expand Up @@ -175,10 +279,12 @@ class Talker implements TalkerInterface {
if (data != null) {
_talkerStreamController.add(data);
_handleForOutputs(data);
_logger.log(
data.generateTextMessage(),
level: data.logLevel ?? LogLevel.debug,
);
if (_settings.useConsoleLogs) {
_logger.log(
data.generateTextMessage(),
level: data.logLevel ?? LogLevel.error,
);
}
}
}
}
51 changes: 51 additions & 0 deletions talker/lib/src/talker_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,58 @@ abstract class TalkerInterface {
String message, {
LogLevel logLevel = LogLevel.debug,
Map<String, dynamic>? additional,
Object? exception,
StackTrace? stackTrace,
AnsiPen? pen,
});

void critical(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void error(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void debug(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void warning(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void verbose(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void info(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void fine(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void good(
String msg, [
Object? exception,
StackTrace? stackTrace,
]);

void cleanHistory();
}
Loading

0 comments on commit 56b17b9

Please sign in to comment.