getLogLineInfo static method
Gets LogLineInfo with stackIndex
which provides data for tag and line of code
Implementation
static LogLineInfo getLogLineInfo({int stackIndex = 4}) {
///([a-zA-Z\<\>\s\.]*)\s\(file:\/(.*\.dart):(\d*):(\d*)
/// group 1 = tag
/// group 2 = filepath
/// group 3 = line number
/// group 4 = column
final stackTraceList = StackTrace.current.toString().split('\n');
if (stackTraceList.length > stackIndex) {
final logline = stackTraceList[stackIndex];
final matches = _logMatcher.allMatches(logline);
if (matches.isNotEmpty) {
final match = matches.first;
return LogLineInfo(
tag: match
.group(1)
?.trim()
.replaceAll('<anonymous closure>', '<ac>') ??
_defaultTag,
logFilePath: match.group(2),
lineNumber: int.tryParse(match.group(3) ?? '-1') ?? -1,
characterIndex: int.tryParse(match.group(4) ?? '-1') ?? -1,
);
} else {
return LogLineInfo(tag: _defaultTag);
}
} else {
return LogLineInfo(tag: _defaultTag);
}
}