This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/utils/logger.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

2019-09-08 19:04:12 +03:00
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
2019-09-08 19:04:12 +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;
}
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) {
Crashlytics.instance.recordError('$message', stacktrace);
2019-09-05 00:17:08 +03:00
}
}
}