Message constructor
Message(])
Implementation
Message(this.message,
this.severity,
this.tag,
this.stackTrace,
this.error,
this.function,
this.fileName,
this.lineNumber,
[Json? json]) : super(LogType.message, json) {
if (error != null) {
final errorStackTrace = StackTraceParser.parse(StackTrace.current.toString());
exception = MessageException(
error.runtimeType.toString(),
error.toString(),
errorStackTrace ?? [],
);
}
if (fileName == null) {
// Frame 0: Message constructor, 1: Log._message, 2: Log.d/message, 3: caller
final frameIndex = 3 + stackOffset;
final stackTraceString = StackTrace.current.toString();
final lines = stackTraceString.split('\n');
if (lines.length > frameIndex) {
final line = lines[frameIndex];
final regex = RegExp(r'#\d+\s+(.+)\s+\((.+?):(\d+)(?::(\d+))?\)');
final match = regex.firstMatch(line);
if (match != null) {
function = match.group(1);
fileName = match.group(2);
lineNumber = int.parse(match.group(3)!);
InnerLog().d('Function: $function FileName: $fileName LineNumber: $lineNumber');
}
}
// Fallback for release builds where stack traces aren't parseable.
// Store the raw caller frame for server-side DWARF symbolication.
if (fileName == null && lines.length > frameIndex && lines[frameIndex].isNotEmpty) {
callerRawFrame = lines[frameIndex];
}
if ((tag == null || tag!.isEmpty) && fileName != null) {
final dotIndex = fileName!.indexOf('.');
tag = dotIndex > 0 ? fileName!.substring(0, dotIndex) : fileName;
}
fileName ??= '';
lineNumber ??= -1;
tag ??= '';
}
}