pub struct SingleSyslog<F = DefaultSyslogFormatter, D = SyslogLocal>where
F: SyslogFormatter,
D: SyslogDestination,{ /* 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
-
D
- a SyslogDestination instance which is either: SyslogLocal, crate::syslog_provider::SyslogFile, [crate::syslog_provider::SyslogNet], crate::syslog_provider::SyslogTls. By default aSyslogLocal
is selected. -
F
- a SyslogFormatter which sets the instance which would format the message.
Implementations§
Source§impl SingleSyslog
impl SingleSyslog
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, D> SingleSyslog<F, D>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> SingleSyslog<F, D>where
F: SyslogFormatter,
D: SyslogDestination,
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 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:
-
Result::Ok - with instance
-
Result::Err - with error description.
Trait Implementations§
Source§impl<F, D> Debug for SingleSyslog<F, D>
impl<F, D> Debug for SingleSyslog<F, D>
Source§impl<'stream, F: SyslogFormatter, D: SyslogDestination> SyStreamApi<'stream, F, D, SingleSyslog<F, D>> for SingleSyslog<F, D>
impl<'stream, F: SyslogFormatter, D: SyslogDestination> SyStreamApi<'stream, F, D, SingleSyslog<F, D>> for SingleSyslog<F, D>
Source§impl<F, D> SyslogApi<F, D> for SingleSyslog<F, D>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> SyslogApi<F, D> for SingleSyslog<F, D>where
F: SyslogFormatter,
D: SyslogDestination,
Source§fn connectlog(&self) -> SyRes<()>
fn connectlog(&self) -> SyRes<()>
Connects the current instance to the syslog server (destination).
Source§fn setlogmask(&self, logmask: i32) -> SyRes<i32>
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 syslog(&self, pri: Priority, fmt: F)
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<()>
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<()>
fn reconnect(&self) -> SyRes<()>
Re-opens the connection to the syslog server. Can be used to rotate logs(handle SIGHUP).
§Returns
-
Result::Ok - with empty inner type.
-
Result::Err - an error code and description
Source§fn update_tap_data(&self, tap_data: D) -> SyRes<()>
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.