Struct Syslog

Source
pub struct Syslog<D = SyslogLocal, S = SyslogShared<DefaultSyslogFormatter, D>>(/* private fields */)
where
    D: SyslogDestination,
    S: SyslogApi<D>;
Expand description

A main instance of the Syslog client.

Implementations§

Source§

impl Syslog

Source

pub fn openlog( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap: SyslogLocal, ) -> SyRes<Self>

Opens a default connection to the local syslog server with default formatter.

§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 - a SyslogLocal instance with configuration.

§Returns

A SyRes is returned (Result) with:

Source§

impl<D: SyslogDestination, F: SyslogFormatter> Syslog<D, SyslogShared<F, D>>

A shared sync instance.

Source

pub fn openlog_with( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap: D, ) -> SyRes<Syslog<D, SyslogShared<F, D>>>

Opens a special connection to the destination syslog server with specific formatter.

All struct generic should be specified before calling this function.

§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 - a destination server. A specific D instance which contains infomation about the destination server. See syslog_provider.rs.

§Returns

A SyRes is returned (Result) with:

Source

pub fn setlogmask(&self, logmask: i32) -> SyRes<i32>

Sets the logmask to filter out the syslog calls. This function behaves differently as it behaves in syslog_sync.rs or syslog_async.rs. It may return an error if: syslog thread had exit and some thread calls this function. Or something happened with channel. This function blocks until the previous mask is received.

See macroses [LOG_MASK] and [LOG_UPTO] to generate mask

§Example

LOG_MASK!(Priority::LOG_EMERG) | LOG_MASK!(Priority::LOG_ERROR)

or

~(LOG_MASK!(Priority::LOG_INFO)) LOG_UPTO!(Priority::LOG_ERROR)

Source

pub fn change_identity(&self, ident: &str) -> SyRes<()>

Changes the identity i.e program name which will appear on the logs.

Can return error if mutex is poisoned.

Source

pub fn closelog(&self) -> SyRes<()>

Closes connection to the syslog server

Source

pub fn syslog(&self, pri: Priority, fmt: String)

Similar to libc, syslog() sends data to syslog server.

§Arguments
  • pri - a priority Priority

  • fmt - a program’s message to be sent as payload.

Source

pub fn vsyslog<M: AsRef<str>>(&self, pri: Priority, fmt: M)

Sends message to syslog (same as syslog).

Source

pub fn reconnect(&self) -> SyRes<()>

Performs the reconnection to the syslog server or file re-open.

§Returns

A Result is retured as SyRes.

Source

pub fn update_tap(&self, new_tap: D) -> SyRes<()>

Updates the inner instance destionation i.e path to file or server address. The type of destination can not be changed.

This function disconnects from syslog server if previously was connected (and reconnects if was connected previously).

§Arguments
§Returns

A SyRes is returned. An error may be returned if:

  • connection to server was failed

  • incorrect type

  • disconnect frm server failed

Source

pub fn make_stream(&self, pri: Priority) -> Box<dyn SyslogStream>

Derives from active syslog intance an fmt::Write instance.

A boxed dyn instance of SyslogStream is returned.

Source§

impl<D: SyslogDestination, F: SyslogFormatter> Syslog<D, SyslogQueue<F, D>>

A queued implementation.

Source

pub fn openlog_with( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap: D, ) -> SyRes<Syslog<D, SyslogQueue<F, D>>>

Opens a special connection to the destination syslog server with specific formatter.

All struct generic should be specified before calling this function.

§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 - a destination server. A specific D instance which contains infomation about the destination server. See syslog_provider.rs.

§Returns

A SyRes is returned (Result) with:

Source

pub fn setlogmask(&self, logmask: i32) -> SyRes<i32>

Sets the logmask to filter out the syslog calls. This function behaves differently as it behaves in syslog_sync.rs or syslog_async.rs. It may return an error if: syslog thread had exit and some thread calls this function. Or something happened with channel. This function blocks until the previous mask is received.

See macroses [LOG_MASK] and [LOG_UPTO] to generate mask

§Example

LOG_MASK!(Priority::LOG_EMERG) | LOG_MASK!(Priority::LOG_ERROR)

or

~(LOG_MASK!(Priority::LOG_INFO)) LOG_UPTO!(Priority::LOG_ERROR)

Source

pub fn closelog(&self) -> SyRes<()>

Closes connection to the syslog server

Source

pub fn syslog(&self, pri: Priority, fmt: String)

Similar to libc, syslog() sends data to syslog server.

§Arguments
  • pri - a priority Priority

  • fmt - a program’s message to be sent as payload.

Source

pub fn vsyslog<M: AsRef<str>>(&self, pri: Priority, fmt: M)

Sends message to syslog (same as syslog).

Source

pub fn reconnect(&self) -> SyRes<()>

Performs the reconnection to the syslog server or file re-open.

§Returns

A Result is retured as SyRes.

Source

pub fn update_tap(&self, new_tap: D) -> SyRes<()>

Updates the inner instance destionation i.e path to file or server address. The type of destination can not be changed.

This function disconnects from syslog server if previously was connected (and reconnects if was connected previously).

§Arguments
§Returns

A SyRes is returned. An error may be returned if:

  • connection to server was failed

  • incorrect type

  • disconnect frm server failed

Source

pub fn make_stream(&self, pri: Priority) -> Box<dyn SyslogStream>

Derives from active syslog intance an fmt::Write instance.

A boxed dyn instance of SyslogStream is returned.

Trait Implementations§

Source§

impl<D, S> Debug for Syslog<D, S>
where D: SyslogDestination + Debug, S: SyslogApi<D> + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D, S> Freeze for Syslog<D, S>
where S: Freeze,

§

impl<D, S> RefUnwindSafe for Syslog<D, S>

§

impl<D, S> Send for Syslog<D, S>

§

impl<D, S> Sync for Syslog<D, S>
where S: Sync, D: Sync,

§

impl<D, S> Unpin for Syslog<D, S>
where S: Unpin, D: Unpin,

§

impl<D, S> UnwindSafe for Syslog<D, S>
where S: UnwindSafe, D: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.