Skip to content

Commit

Permalink
feat: reexport broadcast and native_tls from fasyslog (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: tison <wander4096@gmail.com>
  • Loading branch information
BBArikL and tisonkun authored Nov 17, 2024
1 parent 5453fd2 commit ed0f139
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ rustdoc-args = ["--cfg", "docsrs"]
fastrace = ["dep:fastrace"]
journald = ["dep:libc"]
json = ["dep:serde_json", "dep:serde", "jiff/serde"]
native-tls = ["dep:native-tls", "fasyslog?/native-tls"]
no-color = ["colored/no-color"]
non-blocking = ["dep:crossbeam-channel"]
opentelemetry = [
Expand All @@ -55,8 +56,9 @@ log = { version = "0.4", features = ["std", "kv_unstable"] }
# Optional dependencies
crossbeam-channel = { version = "0.5", optional = true }
fastrace = { version = "0.7", optional = true }
fasyslog = { version = "0.2", optional = true }
fasyslog = { version = "0.3", optional = true }
libc = { version = "0.2.162", optional = true }
native-tls = { version = "0.2", optional = true }
opentelemetry = { version = "0.27", features = ["logs"], optional = true }
opentelemetry-otlp = { version = "0.27", features = [
"logs",
Expand Down
45 changes: 45 additions & 0 deletions src/append/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,51 @@ impl SyslogWriter {
.map(Self::new)
}

/// Create a new syslog writer that broadcast messages to the well-known UDP port (514).
pub fn broadcast_well_known() -> io::Result<SyslogWriter> {
fasyslog::sender::broadcast_well_known()
.map(SyslogSender::Udp)
.map(Self::new)
}

/// Create a new syslog writer that broadcast messages to the given UDP address.
pub fn broadcast(port: u16) -> io::Result<SyslogWriter> {
fasyslog::sender::broadcast(port)
.map(SyslogSender::Udp)
.map(Self::new)
}

/// Create a TLS sender that sends messages to the well-known port (6514).
#[cfg(feature = "native-tls")]
pub fn native_tls_well_known<S: AsRef<str>>(domain: S) -> io::Result<SyslogWriter> {
fasyslog::sender::native_tls_well_known(domain)
.map(SyslogSender::NativeTlsSender)
.map(Self::new)
}

/// Create a TLS sender that sends messages to the given address.
#[cfg(feature = "native-tls")]
pub fn native_tls<A: std::net::ToSocketAddrs, S: AsRef<str>>(
addr: A,
domain: S,
) -> io::Result<SyslogWriter> {
fasyslog::sender::native_tls(addr, domain)
.map(SyslogSender::NativeTlsSender)
.map(Self::new)
}

/// Create a TLS sender that sends messages to the given address with certificate builder.
#[cfg(feature = "native-tls")]
pub fn native_tls_with<A: std::net::ToSocketAddrs, S: AsRef<str>>(
addr: A,
domain: S,
builder: native_tls::TlsConnectorBuilder,
) -> io::Result<SyslogWriter> {
fasyslog::sender::native_tls_with(addr, domain, builder)
.map(SyslogSender::NativeTlsSender)
.map(Self::new)
}

/// Create a new syslog writer that sends messages to the given Unix stream socket.
#[cfg(unix)]
pub fn unix_stream(path: impl AsRef<std::path::Path>) -> io::Result<SyslogWriter> {
Expand Down

0 comments on commit ed0f139

Please sign in to comment.