Skip to main content

Syslog

Struct Syslog 

Source
pub struct Syslog<F = DefaultSyslogFormatter, D = DefaultLocalSyslogDestination, SL = SyShared>{ /* private fields */ }
Expand description

A main sync syslog client instance.

§Generics

  • F - a syslog message formatter. See dir src/formatters for available or define one yourself. A default is DefaultSyslogFormatter.

  • D - a destination server/file. See file src/syslog_provider.rs for available transports. A default is DefaultLocalSyslogDestination.

  • SL - a client type. Sets the mechanism how the resources are shared. There are 3 types of syslog. See info below. Default is SyShared.

§Client types

  • SyShared - is a single FD descriptor which is protected by Mutex. This type can be clonned, moved between threads.

  • SyThreadLocal - is a thread local/lockless type which should be used only in the single thread applications or with std::thread_local only! Can be enabled with feature build_with_thread_local.

  • SyQueued - is a buffering/fast type which uses a separate thread to access the socket’s/file’s FD. This type can be clonned, moved between threads. Can be enabled with feature build_with_queue. Also, it can be used to use the same connection/file from async and sync code, see examples/example_sync_async.rs.

Feature build_with_queue without any async features uses a crossbeam MPSC. If any feature which enables async i.e build_async_tokio, build_async_smol, build_async_interface, the MPSC provider will be switch to either Smoll’s, Tokio’s, or which you will define.

§Examples

Full default:

ⓘ
pub static SYSLOG: LazyLock<Syslog> = LazyLock::new(|| 
{
    #[cfg(target_family = "unix")]
    let syslog_provider = 
        SyslogLocal::new();
 
    #[cfg(target_family = "windows")]   
    let syslog_provider = 
        WindowsEvent::new();
 
    Syslog::openlog(
        Some("example"), 
        LogStat::LOG_CONS | LogStat::LOG_PID, 
        LogFacility::LOG_DAEMON,
        syslog_provider
    )
    .unwrap()
}
);

Custom i.e queued

ⓘ
pub static SYSLOG: LazyLock<Syslog<DefaultSyslogFormatter, DefaultLocalSyslogDestination, SyQueued<DefaultQueueAdapter, DefaultSyslogFormatter, DefaultLocalSyslogDestination>>> = 
LazyLock::new(|| 
    {
        #[cfg(target_family = "unix")]
       let syslog_provider = 
            SyslogLocal::new();
 
        #[cfg(target_family = "windows")]   
        let syslog_provider = 
            WindowsEvent::new();
 
        Syslog
            ::<_, _, SyQueued<DefaultQueueAdapter, _, _>>
            ::openlog_with(
                Some("example_sync_queue"), 
                LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
                LogFacility::LOG_DAEMON,
                syslog_provider
            )
            .unwrap()
    }
 );

Implementations§

Source§

impl<F, D> Syslog<F, D, SyThreadLocal>

Source

pub fn make_dyn(self) -> Box<dyn MutDynSyslog>

Source

pub fn openlog_with( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap_prov: D, ) -> 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_prov - a [SyslogLocal] instance with configuration.

§Returns

A SyRes is returned (Result) with:

Source§

impl<F, D> Syslog<F, D, SyThreadLocal>

Source

pub fn connectlog(&mut self) -> SyRes<()>

Connects the current instance to the syslog server (destination).

Source

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

Sets the logmask to filter out the syslog calls.

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(&mut self) -> SyRes<()>

Closes connection to the syslog server (destination).

Source

pub fn syslog(&mut self, pri: Priority, fmt: F) -> SyRes<()>

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

§Arguments
  • pri - a priority Priority

  • fmt - a formatter SyslogFormatter message. In C exists a functions with variable argumets amount. In Rust you should create your own macros like format!() or use format!()]. The String and ref 'static str can be passed directly.

§Returns

A SyRes is returned which may describe an error.

Source

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

This function can be used to update the facility name, for example after fork().

§Arguments
  • ident - an Option optional new identity (up to 48 UTF8 chars) If set to Option::None would request the program name from OS.
Source

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

Re-opens the connection to the syslog server. Can be used to rotate logs(handle SIGHUP).

§Returns

A Result is retured as SyRes.

Source

pub fn update_tap_data(&mut self, tap_data: D) -> SyRes<()>

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.

Source§

impl<F, D> Syslog<F, D, SyThreadLocal>

Source

pub fn get_stream<'t, PRI>( &'t mut self, ) -> SyStream<'t, PRI, D, F, &'t mut Self> ⓘ
where PRI: SyStreamPri,

Returns the streamable SyStream instance which can be used with write!.

It implements both std::fmt::Write and std::io::Write.

§Example
ⓘ
let log = 
    SingleSyslog::openlog(
        Some("test1"), 
        LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
        LogFacility::LOG_DAEMON,
        SyslogLocal::new()
    ).unwrap();
 
write!(log.get_stream::<SyStreamPriDebug>(), "test stream singlesyslog {}", i).unwrap();
Source§

impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>

Source

pub fn make_dyn(self) -> Box<dyn DynSyslog + Send + Sync>

Converts the current instance into dyncamic object. See DynSyslog for the interface.

Source

pub fn openlog_with( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap_prov: D, ) -> SyRes<Self>

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

§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:

Source§

impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>

Source

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

Connects the current instance to the syslog server (destination).

Source

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

Sets the logmask to filter out the syslog calls.

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 (destination).

Source

pub fn syslog(&self, pri: Priority, fmt: F) -> SyRes<()>

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

§Arguments
  • pri - a priority Priority

  • fmt - a formatter SyslogFormatter message. In C exists a functions with variable argumets amount. In Rust you should create your own macros like format!() or use format!()]. The String and ref 'static str can be passed directly.

§Returns

A SyRes is returned which may describe an error.

Source

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

This function can be used to update the facility name, for example after fork().

§Arguments
  • ident - an Option optional new identity (up to 48 UTF8 chars) If set to Option::None would request the program name from OS.
Source

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

Re-opens the connection to the syslog server. Can be used to rotate logs(handle SIGHUP).

§Returns

A Result is retured as SyRes.

Source

pub fn update_tap_data(&self, tap_data: D) -> SyRes<()>

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.

Source§

impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>

Source

pub fn get_stream<'t, PRI>(&'t self) -> SyStream<'t, PRI, D, F, &'t Self> ⓘ
where PRI: SyStreamPri,

Returns the streamable SyStream instance which can be used with write!.

It implements both std::fmt::Write and std::io::Write.

§Example
ⓘ
let log = 
    SingleSyslog::openlog(
        Some("test1"), 
        LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
        LogFacility::LOG_DAEMON,
        SyslogLocal::new()
    ).unwrap();
 
write!(log.get_stream::<SyStreamPriDebug>(), "test stream singlesyslog {}", i).unwrap();
Source§

impl Syslog

Source

pub fn openlog( ident: Option<&str>, logstat: LogStat, facility: LogFacility, net_tap_prov: DefaultLocalSyslogDestination, ) -> 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:

Source§

impl<F, D> Syslog<F, D, SyShared>

Source

pub fn make_dyn(self) -> Box<dyn DynSyslog + Send + Sync>

Source

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

§Returns

A SyRes is returned (Result) with:

Source

pub fn attach(other: &Syslog<F, D, SyShared>) -> SyRes<Self>

Just initializes the instance from other instance. For example, in the crate which uses this type of logging.

Will work only if F and D are same.

Source§

impl<F, D> Syslog<F, D, SyShared>

Source

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

Connects the current instance to the syslog server (destination).

Source

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

Sets the logmask to filter out the syslog calls.

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 (destination).

Source

pub fn syslog(&self, pri: Priority, fmt: F) -> SyRes<()>

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

§Arguments
  • pri - a priority Priority

  • fmt - a formatter SyslogFormatter message. In C exists a functions with variable argumets amount. In Rust you should create your own macros like format!() or use format!()]. The String and ref 'static str can be passed directly.

§Returns

A SyRes is returned which may describe an error.

Source

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

This function can be used to update the facility name, for example after fork().

§Arguments
  • ident - an Option optional new identity (up to 48 UTF8 chars) If set to Option::None would request the program name from OS.
Source

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

Re-opens the connection to the syslog server. Can be used to rotate logs(handle SIGHUP).

§Returns

A Result is retured as SyRes.

Source

pub fn update_tap_data(&self, tap_data: D) -> SyRes<()>

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.

Source§

impl<F, D> Syslog<F, D, SyShared>

Source

pub fn get_stream<'t, PRI>(&'t self) -> SyStream<'t, PRI, D, F, &'t Self> ⓘ
where PRI: SyStreamPri,

Returns the streamable SyStream instance which can be used with write!.

It implements both std::fmt::Write and std::io::Write.

§Example
ⓘ
let log = 
    SingleSyslog::openlog(
        Some("test1"), 
        LogStat::LOG_CONS | LogStat::LOG_NDELAY | LogStat::LOG_PID, 
        LogFacility::LOG_DAEMON,
        SyslogLocal::new()
    ).unwrap();
 
write!(log.get_stream::<SyStreamPriDebug>(), "test stream singlesyslog {}", i).unwrap();

Trait Implementations§

Source§

impl<F: SyslogFormatter, D: SyslogDestination, S: SyslogQueueChannel<F, D>> AsyncSyslogQueueApi<F, D> for Syslog<F, D, SyQueued<S, F, D>>

Source§

async fn a_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§

async fn a_closelog(&self) -> SyRes<()>

Closes connection to the syslog server

Source§

async fn a_syslog(&self, pri: Priority, fmt: F) -> SyRes<()>

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

§Arguments
  • pri - a priority Priority

  • fmt - a program’s message to be sent as payload. The message is encoded with the SyslogFormatter and may be different for different formatters.

Source§

async fn a_reconnect(&self) -> SyRes<()>

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

§Returns

A Result is retured as SyRes.

Source§

async fn a_update_tap_data(&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§

async fn a_connectlog(&mut self) -> SyRes<()>

Requests to connect to remote server.
Source§

async fn a_change_identity(&self, ident: &str) -> SyRes<()>

This function can be used to update the facility name, for example after fork(). Read more
Source§

impl<F, D> Clone for Syslog<F, D, SyShared>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F, D, S> Clone for Syslog<F, D, SyQueued<S, F, D>>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F, D, SL> Debug for Syslog<F, D, SL>

Source§

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

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

impl<F, D> DynSyslog for Syslog<F, D, SyShared>

Source§

fn connectlog(&self) -> SyRes<()>

Connects the current instance to the syslog server (destination).
Source§

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

Sets the logmask to filter out the syslog calls. Read more
Source§

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

Closes connection to the syslog server (destination).
Source§

fn syslog(&self, pri: Priority, fmt: String) -> SyRes<()>

Similar to libc, syslog() sends data to syslog server. Read more
Source§

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

This function can be used to update the facility name, for example after fork(). Read more
Source§

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

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.
Source§

impl<F, D, S> DynSyslog for Syslog<F, D, SyQueued<S, F, D>>

Source§

fn connectlog(&self) -> SyRes<()>

Connects the current instance to the syslog server (destination).
Source§

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

Sets the logmask to filter out the syslog calls. Read more
Source§

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

Closes connection to the syslog server (destination).
Source§

fn syslog(&self, pri: Priority, fmt: String) -> SyRes<()>

Similar to libc, syslog() sends data to syslog server. Read more
Source§

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

This function can be used to update the facility name, for example after fork(). Read more
Source§

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

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.
Source§

impl<F, D> MutDynSyslog for Syslog<F, D, SyThreadLocal>

Source§

fn connectlog(&mut self) -> SyRes<()>

Connects the current instance to the syslog server (destination).
Source§

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

Sets the logmask to filter out the syslog calls. Read more
Source§

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

Closes connection to the syslog server (destination).
Source§

fn syslog(&mut self, pri: Priority, fmt: String) -> SyRes<()>

Similar to libc, syslog() sends data to syslog server. Read more
Source§

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

This function can be used to update the facility name, for example after fork(). Read more
Source§

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

Updates the instance’s socket. tap_data [TapTypeData] should be of the same variant (type) as current.
Source§

impl<F, D> SyStreamSyslogApi<F, D> for &mut Syslog<F, D, SyThreadLocal>

Source§

type SYSLOG<'t> = &'t mut Syslog<F, D, SyThreadLocal>

A type which declared wither syslog instance can be mutable or not.
Source§

fn syslog<'t>(syslog: Self::SYSLOG<'t>, pri: Priority, fmt: F) -> SyRes<()>

Sends message to syslog server over channel.
Source§

impl<F: SyslogFormatter, D: SyslogDestination> SyStreamSyslogApi<F, D> for &Syslog<F, D, SyShared>

Source§

type SYSLOG<'t> = &'t Syslog<F, D>

A type which declared wither syslog instance can be mutable or not.
Source§

fn syslog<'t>(syslog: Self::SYSLOG<'t>, pri: Priority, fmt: F) -> SyRes<()>

Sends message to syslog server over channel.
Source§

impl<F, D, S> SyStreamSyslogApi<F, D> for &Syslog<F, D, SyQueued<S, F, D>>

Source§

type SYSLOG<'t> = &'t Syslog<F, D, SyQueued<S, F, D>>

A type which declared wither syslog instance can be mutable or not.
Source§

fn syslog<'t>(syslog: Self::SYSLOG<'t>, pri: Priority, fmt: F) -> SyRes<()>

Sends message to syslog server over channel.

Auto Trait Implementations§

§

impl<F, D, SL> Freeze for Syslog<F, D, SL>

§

impl<F, D, SL> RefUnwindSafe for Syslog<F, D, SL>

§

impl<F, D, SL> Send for Syslog<F, D, SL>

§

impl<F, D, SL> Sync for Syslog<F, D, SL>

§

impl<F, D, SL> Unpin for Syslog<F, D, SL>

§

impl<F, D, SL> UnsafeUnpin for Syslog<F, D, SL>

§

impl<F, D, SL> UnwindSafe for Syslog<F, D, SL>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.