pub struct Syslog<F = DefaultSyslogFormatter, D = DefaultLocalSyslogDestination, SL = SyShared>{ /* private fields */ }Implementations§
Source§impl<F, D> Syslog<F, D, SyThreadLocal>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyThreadLocal>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.
Source§impl<F, D> Syslog<F, D, SyThreadLocal>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyThreadLocal>where
F: SyslogFormatter,
D: SyslogDestination,
Sourcepub fn connectlog(&mut self) -> SyRes<()>
pub fn connectlog(&mut self) -> SyRes<()>
Connects the current instance to the syslog server (destination).
Sourcepub fn setlogmask(&mut self, logmask: i32) -> SyRes<i32>
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)
Sourcepub fn syslog(&mut self, pri: Priority, fmt: F) -> SyRes<()>
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'staticstr can be passed directly.
§Returns
A SyRes is returned which may describe an error.
Sourcepub fn change_identity(&mut self, ident: Option<&str>) -> SyRes<()>
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.
Sourcepub fn reconnect(&mut self) -> SyRes<()>
pub fn reconnect(&mut 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
Sourcepub fn update_tap_data(&mut self, tap_data: D) -> SyRes<()>
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>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyThreadLocal>where
F: SyslogFormatter,
D: SyslogDestination,
Sourcepub fn get_stream<'t, PRI>(
&'t mut self,
) -> SyStream<'t, PRI, D, F, &'t mut Self> ⓘwhere
PRI: SyStreamPri,
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>>
impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>
Sourcepub fn make_dyn(self) -> Box<dyn DynSyslog>
pub fn make_dyn(self) -> Box<dyn DynSyslog>
Converts the current instance into dyncamic object. See DynSyslog for the interface.
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 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:
-
Result::Ok - with instance
-
Result::Err - with error description.
Source§impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>
impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>
Sourcepub fn connectlog(&self) -> SyRes<()>
pub fn connectlog(&self) -> SyRes<()>
Connects the current instance to the syslog server (destination).
Sourcepub fn setlogmask(&self, logmask: i32) -> SyRes<i32>
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)
Sourcepub fn syslog(&self, pri: Priority, fmt: F) -> SyRes<()>
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'staticstr can be passed directly.
§Returns
A SyRes is returned which may describe an error.
Sourcepub fn change_identity(&self, ident: Option<&str>) -> SyRes<()>
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.
Sourcepub fn reconnect(&self) -> SyRes<()>
pub 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
Sourcepub fn update_tap_data(&self, tap_data: D) -> SyRes<()>
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>>
impl<F, D, S> Syslog<F, D, SyQueued<S, F, D>>
Sourcepub fn get_stream<'t, PRI>(&'t self) -> SyStream<'t, PRI, D, F, &'t Self> ⓘwhere
PRI: SyStreamPri,
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
impl Syslog
Sourcepub fn openlog(
ident: Option<&str>,
logstat: LogStat,
facility: LogFacility,
net_tap_prov: DefaultLocalSyslogDestination,
) -> SyRes<Self>
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:
-
Result::Ok - with instance
-
Result::Err - with error description.
Source§impl<F, D> Syslog<F, D, SyShared>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyShared>where
F: SyslogFormatter,
D: SyslogDestination,
pub fn make_dyn(self) -> Box<dyn DynSyslog>
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 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 specificDinstance which contains infomation about the destination server. Seesyslog_provider.rs.
§Returns
A SyRes is returned (Result) with:
-
Result::Ok - with instance
-
Result::Err - with error description.
Source§impl<F, D> Syslog<F, D, SyShared>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyShared>where
F: SyslogFormatter,
D: SyslogDestination,
Sourcepub fn connectlog(&self) -> SyRes<()>
pub fn connectlog(&self) -> SyRes<()>
Connects the current instance to the syslog server (destination).
Sourcepub fn setlogmask(&self, logmask: i32) -> SyRes<i32>
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)
Sourcepub fn syslog(&self, pri: Priority, fmt: F) -> SyRes<()>
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'staticstr can be passed directly.
§Returns
A SyRes is returned which may describe an error.
Sourcepub fn change_identity(&self, ident: Option<&str>) -> SyRes<()>
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.
Sourcepub fn reconnect(&self) -> SyRes<()>
pub 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
Sourcepub fn update_tap_data(&self, tap_data: D) -> SyRes<()>
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>where
F: SyslogFormatter,
D: SyslogDestination,
impl<F, D> Syslog<F, D, SyShared>where
F: SyslogFormatter,
D: SyslogDestination,
Sourcepub fn get_stream<'t, PRI>(&'t self) -> SyStream<'t, PRI, D, F, &'t Self> ⓘwhere
PRI: SyStreamPri,
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>>
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>
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<()>
async fn a_closelog(&self) -> SyRes<()>
Closes connection to the syslog server
Source§async fn a_syslog(&self, pri: Priority, fmt: F) -> SyRes<()>
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<()>
async fn a_reconnect(&self) -> SyRes<()>
Performs the reconnection to the syslog server or file re-open.
§Returns
-
Result::Ok - with empty inner type.
-
Result::Err - an error code and description
Source§async fn a_update_tap_data(&self, new_tap: D) -> SyRes<()>
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
new_tap- a consumed instance of typeDSyslogDestination
§Returns
A SyRes is returned. An error may be returned if:
-
connection to server was failed
-
incorrect type
-
disconnect frm server failed