startLoki method
Starts Loki for pushing logs.
If Loki is not configured, a warning message will be logged.
Implementation
Future<void> startLoki() async {
if (!lokiEnabled) {
Logger(
service: _loggerServiceName,
options: options,
defaultModule: 'one_logger')
.warn('Loki URL not configured');
return;
}
final receiverPort = ReceivePort();
final isolate = await Isolate.spawn(pushIsolate,
Tuple4(receiverPort.sendPort, lokiOptions!, service, options),
debugName: 'Grafana Loki Pusher');
try {
final port = receiverPort.asBroadcastStream();
final sendPort = await port.first;
if (!_sendPorts.containsKey(lokiOptions)) {
_sendPorts[lokiOptions!] = sendPort;
}
port.listen((message) {
if (message == 'done') {
receiverPort.close();
}
});
} catch (_) {
isolate.kill();
}
}