fix: minor bugs
This commit is contained in:
@@ -104,8 +104,8 @@ class CustomToast extends StatelessWidget {
|
||||
}
|
||||
|
||||
void show(BuildContext context) {
|
||||
FToast().init(context);
|
||||
FToast().showToast(
|
||||
final fToast = FToast().init(context);
|
||||
fToast.showToast(
|
||||
child: this,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
toastDuration: duration,
|
||||
|
||||
@@ -3,15 +3,24 @@ import 'dart:io';
|
||||
import 'package:loggy/loggy.dart';
|
||||
|
||||
class MultiLogPrinter extends LoggyPrinter {
|
||||
MultiLogPrinter(this.consolePrinter, this.filePrinter);
|
||||
MultiLogPrinter(
|
||||
this.consolePrinter,
|
||||
this.otherPrinters,
|
||||
);
|
||||
|
||||
final LoggyPrinter consolePrinter;
|
||||
final LoggyPrinter? filePrinter;
|
||||
List<LoggyPrinter> otherPrinters;
|
||||
|
||||
void addPrinter(LoggyPrinter printer) {
|
||||
otherPrinters.add(printer);
|
||||
}
|
||||
|
||||
@override
|
||||
void onLog(LogRecord record) {
|
||||
consolePrinter.onLog(record);
|
||||
filePrinter?.onLog(record);
|
||||
for (final printer in otherPrinters) {
|
||||
printer.onLog(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
95
lib/utils/sentry_loggy_integration.dart
Normal file
95
lib/utils/sentry_loggy_integration.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:loggy/loggy.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
// modified version of https://github.com/getsentry/sentry-dart/tree/main/logging
|
||||
class SentryLoggyIntegration extends LoggyPrinter
|
||||
implements Integration<SentryOptions> {
|
||||
SentryLoggyIntegration({
|
||||
LogLevel minBreadcrumbLevel = LogLevel.info,
|
||||
LogLevel minEventLevel = LogLevel.error,
|
||||
}) : _minBreadcrumbLevel = minBreadcrumbLevel,
|
||||
_minEventLevel = minEventLevel;
|
||||
|
||||
final LogLevel _minBreadcrumbLevel;
|
||||
final LogLevel _minEventLevel;
|
||||
|
||||
late Hub _hub;
|
||||
|
||||
@override
|
||||
void call(Hub hub, SentryOptions options) {
|
||||
_hub = hub;
|
||||
options.sdk.addIntegration('LoggyIntegration');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {}
|
||||
|
||||
bool _shouldLog(LogLevel logLevel, LogLevel minLevel) {
|
||||
if (logLevel == LogLevel.off) {
|
||||
return false;
|
||||
}
|
||||
return logLevel.priority >= minLevel.priority;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onLog(LogRecord record) async {
|
||||
if (_shouldLog(record.level, _minEventLevel)) {
|
||||
await _hub.captureEvent(
|
||||
record.toEvent(),
|
||||
stackTrace: record.stackTrace,
|
||||
hint: Hint.withMap({TypeCheckHint.record: record}),
|
||||
);
|
||||
}
|
||||
|
||||
if (_shouldLog(record.level, _minBreadcrumbLevel)) {
|
||||
await _hub.addBreadcrumb(
|
||||
record.toBreadcrumb(),
|
||||
hint: Hint.withMap({TypeCheckHint.record: record}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension LogRecordX on LogRecord {
|
||||
Breadcrumb toBreadcrumb() {
|
||||
return Breadcrumb(
|
||||
category: 'log',
|
||||
type: 'debug',
|
||||
timestamp: time.toUtc(),
|
||||
level: level.toSentryLevel(),
|
||||
message: message,
|
||||
data: <String, Object>{
|
||||
if (object != null) 'LogRecord.object': object!,
|
||||
if (error != null) 'LogRecord.error': error!,
|
||||
if (stackTrace != null) 'LogRecord.stackTrace': stackTrace!,
|
||||
'LogRecord.loggerName': loggerName,
|
||||
'LogRecord.sequenceNumber': sequenceNumber,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
SentryEvent toEvent() {
|
||||
return SentryEvent(
|
||||
timestamp: time.toUtc(),
|
||||
logger: loggerName,
|
||||
level: level.toSentryLevel(),
|
||||
message: SentryMessage(message),
|
||||
throwable: error,
|
||||
// ignore: deprecated_member_use
|
||||
extra: <String, Object>{
|
||||
if (object != null) 'LogRecord.object': object!,
|
||||
'LogRecord.sequenceNumber': sequenceNumber,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension LogLevelX on LogLevel {
|
||||
SentryLevel? toSentryLevel() => switch (this) {
|
||||
LogLevel.all || LogLevel.debug => SentryLevel.debug,
|
||||
LogLevel.info => SentryLevel.info,
|
||||
LogLevel.warning => SentryLevel.warning,
|
||||
LogLevel.error => SentryLevel.error,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@ export 'mutation_state.dart';
|
||||
export 'number_formatters.dart';
|
||||
export 'placeholders.dart';
|
||||
export 'platform_utils.dart';
|
||||
export 'sentry_loggy_integration.dart';
|
||||
export 'text_utils.dart';
|
||||
export 'uri_utils.dart';
|
||||
export 'validators.dart';
|
||||
|
||||
Reference in New Issue
Block a user