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
2020-05-06 17:24:13 +00:00

44 lines
1.1 KiB
Dart

import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
enum ErrorLevel {ERROR, WARNING, DEBUG}
class Logger {
static bool get isInDebugMode {
bool inDebugMode = false;
assert(inDebugMode = true);
return inDebugMode;
}
static void p(data) {
print(data);
}
static void e(dynamic message, {dynamic stacktrace, bool skipCrashlytics: false}) {
_writeToLog(ErrorLevel.ERROR, message.toString(), stacktrace, skipCrashlytics);
}
static void w(String message) {
_writeToLog(ErrorLevel.WARNING, message, null, true);
}
static void d(String message) {
_writeToLog(ErrorLevel.DEBUG, message, null, true);
}
static void _writeToLog(ErrorLevel level, String message, dynamic stacktrace, bool skipCrashlytics) {
if (isInDebugMode) {
debugPrint('$message');
if (stacktrace != null) {
debugPrint('$stacktrace');
}
} else if (!skipCrashlytics) {
Crashlytics.instance.recordError('$message', stacktrace);
}
}
}