Refactor logs

This commit is contained in:
problematicconsumer
2023-11-28 18:24:31 +03:30
parent bb745c2ec1
commit 9c165e178b
25 changed files with 272 additions and 163 deletions

View File

@@ -0,0 +1,33 @@
// ignore_for_file: parameter_assignments
import 'package:dartx/dartx.dart';
import 'package:hiddify/features/log/model/log_entity.dart';
import 'package:hiddify/features/log/model/log_level.dart';
import 'package:tint/tint.dart';
abstract class LogParser {
static LogEntity parseSingbox(String log) {
log = log.strip();
DateTime? time;
if (log.length > 25) {
time = DateTime.tryParse(log.substring(6, 25));
}
if (time != null) {
log = log.substring(26);
}
final level = LogLevel.values.firstOrNullWhere(
(e) {
if (log.startsWith(e.name.toUpperCase())) {
log = log.removePrefix(e.name.toUpperCase());
return true;
}
return false;
},
);
return LogEntity(
level: level,
time: time,
message: log.trim(),
);
}
}