pub struct SyShared;Expand description
A sync, shared instance of the syslog client which is shared between many
threads. Previously a mutex was used, but since the v5.0.0 a CoW experimental
approach is used. The CoW creates clones of the instance without holding
a long mutex locks. When writing, the instance does not hold a long lock on
updated item. Only exclusive lock locks the readers, because the instance is
updated and not usable anyway.
If the program has fixed amount of threads, probably the syslog_threadlocal
will be better alternative. It has the same functionality, but avoids
any sync locks by working in current thread.
§Traits
For this isntance a [SyslogApi] and [SyStreamApi] are implemented.
§Examples
let log =
Syslog::openlog(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
);let log =
Syslog
::<DefaultSyslogFormatter, SyslogLocal, SyShared>
::openlog_with(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
);pub static SYSLOG3: LazyLock<Syslog<DefaultSyslogFormatter, SyslogLocal, SyShared>> =
LazyLock::new(||
{
Syslog
::<DefaultSyslogFormatter, SyslogLocal, SyShared>
::openlog_with(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
)
.unwrap()
}
);§Streaming
A stream is availble via [SyStreamApi].
let _ = write!(SYSLOG.stream(Priority::LOG_DEBUG), "test {} 123 stream test ", d);§Generics
-
F- a SyslogFormatter which sets the instance which would format the message. -
D- a SyslogDestination instance which is either: [SyslogLocal], [SyslogFile], [SyslogNet], [SyslogTls]. By default aSyslogLocalis selected.