Skip to main content

SyShared

Struct SyShared 

Source
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 a SyslogLocal is selected.

Trait Implementations§

Source§

impl Debug for SyShared

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SyslogType for SyShared

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.