2019-09-08 19:04:12 +03:00
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-05-01 17:34:31 +03:00
|
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
2019-09-08 19:04:12 +03:00
|
|
|
|
2020-05-01 17:34:31 +03:00
|
|
|
enum ErrorLevel {ERROR, WARNING, DEBUG}
|
2019-09-05 00:17:08 +03:00
|
|
|
|
|
|
|
class Logger {
|
|
|
|
|
|
|
|
static bool get isInDebugMode {
|
|
|
|
bool inDebugMode = false;
|
|
|
|
|
|
|
|
assert(inDebugMode = true);
|
|
|
|
|
|
|
|
return inDebugMode;
|
|
|
|
}
|
|
|
|
|
2019-11-27 14:26:55 +02:00
|
|
|
static void p(data) {
|
|
|
|
print(data);
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:24:13 +03:00
|
|
|
static void e(dynamic message, {dynamic stacktrace, bool skipCrashlytics: false}) {
|
|
|
|
_writeToLog(ErrorLevel.ERROR, message.toString(), stacktrace, skipCrashlytics);
|
2019-09-05 00:17:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void w(String message) {
|
2020-05-01 19:24:13 +03:00
|
|
|
_writeToLog(ErrorLevel.WARNING, message, null, true);
|
2019-09-05 00:17:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d(String message) {
|
2020-05-01 19:24:13 +03:00
|
|
|
_writeToLog(ErrorLevel.DEBUG, message, null, true);
|
2019-09-05 00:17:08 +03:00
|
|
|
}
|
|
|
|
|
2020-05-01 19:24:13 +03:00
|
|
|
static void _writeToLog(ErrorLevel level, String message, dynamic stacktrace, bool skipCrashlytics) {
|
2019-09-05 00:17:08 +03:00
|
|
|
if (isInDebugMode) {
|
|
|
|
debugPrint('$message');
|
2020-05-04 17:47:47 +03:00
|
|
|
if (stacktrace != null) {
|
|
|
|
debugPrint('$stacktrace');
|
|
|
|
}
|
2020-05-01 19:24:13 +03:00
|
|
|
} else if (!skipCrashlytics) {
|
2020-05-01 17:34:31 +03:00
|
|
|
Crashlytics.instance.recordError('$message', stacktrace);
|
2019-09-05 00:17:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|