error method
void
error(})
Logs an error message
with LogLevel.error as debugPrint.
Also tries to send the log with optional error, stackTrace
and fatal
boolean to your
CrashReportsInterface implementation should you have configured one with the
Loglytics.setUp method.
Implementation
void error(
String message, {
String? location,
Object? error,
StackTrace? stackTrace,
bool fatal = false,
bool printStack = true,
bool addToCrashReports = true,
bool forceRecordError = false,
String? tag,
}) {
var logLevel = fatal ? LogLevel.fatal : LogLevel.error;
if (level.skipLog(logLevel)) return;
StackTrace localStackTrace;
try {
localStackTrace = stackTrace ??
StackTrace.fromString(
StackTrace.current.toString().split('\n').sublist(1).join('\n'),
);
} catch (error) {
localStackTrace = StackTrace.current;
}
final hasError = error != null;
if (hasError || forceRecordError) {
_eventBus.tryAddCrashReport(
Loglytics._crashReportsInterface?.recordError(
error,
localStackTrace,
fatal: fatal,
),
);
}
_logMessage(
message: message,
logLevel: logLevel,
addToCrashReports: addToCrashReports,
location: location,
tag: tag,
);
if (hasError) {
_logMessage(
message: error.toString(),
logLevel: logLevel,
addToCrashReports: false,
location: location,
tag: tag,
);
}
if (printStack) {
debugPrintStack(
stackTrace: stackTrace,
maxFrames: _maxLinesStackTrace,
);
}
}