pub struct SyncSyslog<F = DefaultSyslogFormatter, D = SyslogLocal>where
F: SyslogFormatter,
D: SyslogDestination,{ /* private fields */ }
Expand description
A sync, shared instance of the syslog client which is shared between threads. Previously a mutex was used, but since the v5.0.0 a CoW experimental approach is used.
For this isntance a SyslogApi and SyStreamApi are implemented.
let log =
SyncSyslog::openlog(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
);
let log =
SyncSyslog
::<DefaultSyslogFormatter, SyslogLocal>
::openlog_with(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
);
pub static SYSLOG3: LazyLock<SyncSyslog<DefaultSyslogFormatter, SyslogLocal,>> =
LazyLock::new(||
{
SyncSyslog
::<DefaultSyslogFormatter, SyslogLocal>
::openlog_with(
Some("test1"),
LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID,
LogFacility::LOG_DAEMON,
SyslogLocal::new()
)
.unwrap()
}
);
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 aSyslogLocal
is selected.
Implementations§
Source§impl SyncSyslog
impl SyncSyslog
Sourcepub fn openlog(
ident: Option<&str>,
logstat: LogStat,
facility: LogFacility,
net_tap_prov: SyslogLocal,
) -> SyRes<Self>
pub fn openlog( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap_prov: SyslogLocal, ) -> SyRes<Self>
Opens a default connection to the local syslog server with default formatter.
In order to access the syslog API, use the SyslogApi.
§Arguments
-
ident
- A program name which will appear on the logs. If none, will be determined automatically. -
logstat
- LogStat an instance config. -
facility
- LogFacility a syslog facility. -
net_tap_prov
- a SyslogLocal instance with configuration.
§Returns
A SyRes is returned (Result) with:
-
Result::Ok - with instance
-
Result::Err - with error description.
Source§impl<F: SyslogFormatter, D: SyslogDestination> SyncSyslog<F, D>
impl<F: SyslogFormatter, D: SyslogDestination> SyncSyslog<F, D>
Sourcepub fn openlog_with(
ident: Option<&str>,
logstat: LogStat,
facility: LogFacility,
net_tap_prov: D,
) -> SyRes<Self>
pub fn openlog_with( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap_prov: D, ) -> SyRes<Self>
Opens a special connection to the destination syslog server with specific formatter.
All struct generic should be specified before calling this function.
In order to access the syslog API, use the SyslogApi.
§Arguments
-
ident
- A program name which will appear on the logs. If none, will be determined automatically. -
logstat
- LogStat an instance config. -
facility
- LogFacility a syslog facility. -
net_tap_prov
- a destination server. A specificD
instance which contains infomation about the destination server. Seesyslog_provider.rs
.
§Returns
A SyRes is returned (Result) with:
-
Result::Ok - with instance
-
Result::Err - with error description.
Trait Implementations§
Source§impl<F, D> Clone for SyncSyslog<F, D>
impl<F, D> Clone for SyncSyslog<F, D>
Source§fn clone(&self) -> SyncSyslog<F, D>
fn clone(&self) -> SyncSyslog<F, D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F, D> Debug for SyncSyslog<F, D>
impl<F, D> Debug for SyncSyslog<F, D>
Source§impl<'stream, F: SyslogFormatter, D: SyslogDestination> SyStreamApi<'stream, F, D, SyncSyslog<F, D>> for SyncSyslog<F, D>
impl<'stream, F: SyslogFormatter, D: SyslogDestination> SyStreamApi<'stream, F, D, SyncSyslog<F, D>> for SyncSyslog<F, D>
Source§impl<F: SyslogFormatter, D: SyslogDestination> SyslogApi<F, D> for SyncSyslog<F, D>
impl<F: SyslogFormatter, D: SyslogDestination> SyslogApi<F, D> for SyncSyslog<F, D>
Source§fn change_identity(&self, ident: Option<&str>) -> SyRes<()>
fn change_identity(&self, ident: Option<&str>) -> SyRes<()>
This function can be used to update the facility name, for example after fork().
§Arguments
ident
- a new identity (up to 48 UTF8 chars)
Source§fn connectlog(&self) -> SyRes<()>
fn connectlog(&self) -> SyRes<()>
Source§fn setlogmask(&self, logmask: i32) -> SyRes<i32>
fn setlogmask(&self, logmask: i32) -> SyRes<i32>
Source§fn syslog(&self, pri: Priority, fmt: F)
fn syslog(&self, pri: Priority, fmt: F)
Source§fn reconnect(&self) -> SyRes<()>
fn reconnect(&self) -> SyRes<()>
Source§fn update_tap_data(&self, tap_data: D) -> SyRes<()>
fn update_tap_data(&self, tap_data: D) -> SyRes<()>
tap_data
[TapTypeData] should be of
the same variant (type) as current.