send method
Send message
with severity
and facility
or facilityInt
(for custom facility) to the syslog server.
tags
can be used to override the values passed to SyslogUdpClient constructor.
If msgId
or structuredData
are used, the message is sent using RFC 5424.
Implementation
Future<void> send(Severity severity, String message,
{Facility? facility,
int? facilityInt,
DateTime? timeStamp,
SyslogTags? tags,
String? msgId,
String? structuredData}) async {
facilityInt ??= facility?.index;
assert(facilityInt != null);
final priority = facilityInt! * 8 + severity.index;
const version = 1;
timeStamp ??= DateTime.now();
timeStamp = timeStamp.toUtc();
final hostName = tags?.hostName ?? this.tags?.hostName ?? '-';
final appName = tags?.appName ?? this.tags?.appName ?? '-';
final procId = tags?.procId ?? this.tags?.procId ?? '-';
final hasMessageId = msgId != null;
msgId ??= '-';
final hasStructuredData = structuredData != null;
structuredData = hasStructuredData ? '[$structuredData]' : '-';
final useRfc5424 = this.useRfc5424 || hasMessageId || hasStructuredData;
final m = useRfc5424
? '<$priority>$version ${timeStamp.toIso8601String()} $hostName $appName $procId $msgId $structuredData $message'
: '<$priority>${_dateFormatForRfc3164.format(timeStamp)} $hostName $appName[$procId]: $message';
await init();
_soc!.send(utf8.encode(m), address, port);
}