SingleSyslog

Struct SingleSyslog 

Source
pub struct SingleSyslog<F = DefaultSyslogFormatter, D = SyslogLocal>{ /* private fields */ }
Expand description

A threal local syslog which is completely lockless! It can be used in signle threaded applications or with the thread_local functionality.

thread_local! 
{
    // Could add pub to make it public to whatever Foo already is public to.
    static SYSLOG: RefCell<SingleSyslog> = 
        RefCell::new(SingleSyslog::openlog_with(Some("test"), 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);

The instances will be completly separated and have own FD.

§Generics

Implementations§

Source§

impl SingleSyslog

Source

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:

Source§

impl<F, D> SingleSyslog<F, D>

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:

Trait Implementations§

Source§

impl<F, D> Debug for SingleSyslog<F, D>

Source§

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

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

impl<'stream, F: SyslogFormatter, D: SyslogDestination> SyStreamApi<'stream, F, D, SingleSyslog<F, D>> for SingleSyslog<F, D>

Source§

fn stream( &'stream self, pri: Priority, ) -> SyStream<'stream, D, F, SingleSyslog<F, D>>

Creates the temporary structure which holds the Priority and implements std::fmt::Write. A SyStream is returned which can be used directly with write. Read more
Source§

impl<F, D> SyslogApi<F, D> for SingleSyslog<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.

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§

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

Closes connection to the syslog server (destination).

Source§

fn syslog(&self, pri: Priority, fmt: F)

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.

Source§

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§

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§

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.

Auto Trait Implementations§

§

impl<F = FormatRfc3146, D = SyslogLocal> !Freeze for SingleSyslog<F, D>

§

impl<F = FormatRfc3146, D = SyslogLocal> !RefUnwindSafe for SingleSyslog<F, D>

§

impl<F = FormatRfc3146, D = SyslogLocal> !Send for SingleSyslog<F, D>

§

impl<F = FormatRfc3146, D = SyslogLocal> !Sync for SingleSyslog<F, D>

§

impl<F, D> Unpin for SingleSyslog<F, D>

§

impl<F, D> UnwindSafe for SingleSyslog<F, D>

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.