emitLog method
Performs the actual delivery of event to the transport's destination.
Called only when event.level >= this.level. Implementations must not
throw; swallow or handle errors internally.
Implementation
@override
Future<void> emitLog(LogEvent event) async {
try {
final payload = serializer != null
? serializer!(event)
: _defaultPayload(event);
final uri = Uri.parse(endpoint);
final client = HttpClient();
if (proxy != null) {
client.findProxy = (_) => 'PROXY $proxy;';
}
final request = await client.postUrl(uri);
headers.forEach((k, v) => request.headers.set(k, v));
request.headers.set('Content-Type', 'application/json');
request.add(utf8.encode(jsonEncode(payload)));
if (timeout != null) {
final response = await request.close().timeout(
Duration(milliseconds: timeout!),
);
await response.drain<void>();
} else {
final response = await request.close();
await response.drain<void>();
}
client.close();
} catch (_) {
// Swallow transport errors to avoid disrupting the application.
}
}