readLogs static method
Reads log entries from a file in JSON Lines format.
The dirPath
parameter specifies the directory path where the log file is
located, and the type
parameter specifies the log file prefix (e.g., 'simple'
or 'network'). The method returns a list of log entries, where each entry is
a Map<String, dynamic>
containing the log data.
If the file does not exist, an empty list is returned.
Implementation
static Future<List<Map<String, dynamic>>> readLogs(
String dirPath, String type) async {
final file = File('$dirPath/${type}_logs.jsonl');
if (!await file.exists()) return [];
final lines = await file.readAsLines();
return lines
.map((line) => jsonDecode(line) as Map<String, dynamic>)
.toList();
}