Files
lunasea/lib/system/logger.dart
Jagandeep Brar 9dc1099742 [Logger] Implemented On-Device Logger (#44)
* [Packages] Added f_logs
* [Logger] Initialized, captures crashes
* [State, Logger] Safe-guarded setState, added logger tab in settings
* [Logs] Implemented logs page, log types page, stub log view page
* [Logs] Added log types page, log view page, stub log details page
* [Logger] Finished details view
* [Logger] Removed info logging
* [Lidarr] Added logging to API calls
* [Radarr] Added logging to API calls
* [ListTiles] Added arrows for ListTiles that have more text
* [Sonarr] Added logging to API calls
* [Sonarr] Safetied some calculations
* [SABnzbd] Added logging to API calls
* [Sonarr] Prevent dividing by zero

Closes #38
2020-01-06 17:30:17 -06:00

63 lines
2.0 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:f_logs/f_logs.dart';
class Logger {
Logger._();
static void initialize() {
LogsConfig config = FLog.getDefaultConfigurations()
..formatType = FormatType.FORMAT_SQUARE
..timestampFormat = 'MMMM dd, y - hh:mm:ss a';
FLog.applyConfigurations(config);
FlutterError.onError = (FlutterErrorDetails details) async {
bool inDebugMode = false;
assert(inDebugMode = true);
if (inDebugMode) {
FlutterError.dumpErrorToConsole(details);
}
Zone.current.handleUncaughtError(details.exception, details.stack);
};
}
static void warning(String className, String methodName, String text, {DataLogType type = DataLogType.DEFAULT}) {
FLog.warning(
className: className,
methodName: methodName,
text: text,
dataLogType: type.toString(),
);
}
static void error(String className, String methodName, String text, Object error, StackTrace trace, {DataLogType type = DataLogType.DEFAULT}) {
FLog.error(
className: className,
methodName: methodName,
text: text,
exception: Exception(error.toString()),
stacktrace: trace,
dataLogType: type.toString(),
);
}
static void fatal(Object error, StackTrace trace, {DataLogType type = DataLogType.DEFAULT}) {
FLog.fatal(
className: Trace.from(trace).frames[1].uri.toString() ?? 'Unknown',
methodName: Trace.from(trace).frames[1].member.toString() ?? 'Unknown',
text: error.toString(),
exception: Exception(error.toString()),
stacktrace: trace,
dataLogType: type.toString(),
);
}
static void exportLogs() {
FLog.exportLogs();
}
static void clearLogs() {
FLog.clearLogs();
}
}