Files
umbrix/lib/utils/custom_log_printer.dart

42 lines
851 B
Dart
Raw Normal View History

2023-08-19 22:27:23 +03:30
import 'dart:io';
import 'package:loggy/loggy.dart';
class MultiLogPrinter extends LoggyPrinter {
2023-09-18 14:01:44 +03:30
MultiLogPrinter(
this.consolePrinter,
this.otherPrinters,
);
2023-08-19 22:27:23 +03:30
final LoggyPrinter consolePrinter;
2023-09-18 14:01:44 +03:30
List<LoggyPrinter> otherPrinters;
void addPrinter(LoggyPrinter printer) {
otherPrinters.add(printer);
}
2023-08-19 22:27:23 +03:30
@override
void onLog(LogRecord record) {
consolePrinter.onLog(record);
2023-09-18 14:01:44 +03:30
for (final printer in otherPrinters) {
printer.onLog(record);
}
2023-08-19 22:27:23 +03:30
}
}
class FileLogPrinter extends LoggyPrinter {
FileLogPrinter(String filePath) : _logFile = File(filePath);
final File _logFile;
late final _sink = _logFile.openWrite(
mode: FileMode.writeOnly,
);
@override
void onLog(LogRecord record) {
2023-08-22 23:50:33 +03:30
final time = record.time.toIso8601String().split('T')[1];
_sink.writeln("$time - $record");
2023-08-19 22:27:23 +03:30
}
}