Struct Logger

Source
pub struct Logger<Backend: Write, Formatter> {
    pub formatter: Formatter,
    pub backend: Backend,
}
Expand description

Main logging structure

Fields§

§formatter: Formatter§backend: Backend

Implementations§

Source§

impl<W: Write, F> Logger<W, F>

Source

pub fn new(backend: W, formatter: F) -> Self

Source

pub fn send<T>(&mut self, severity: Severity, message: &T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn send_at<T>( &mut self, severity: Severity, time: OffsetDateTime, message: &T, ) -> Result<()>
where F: LogFormat<T>,

Source

pub fn emerg<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn alert<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn crit<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn err<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Examples found in repository?
examples/write.rs (line 17)
5fn main() {
6    let formatter = Formatter3164 {
7        facility: Facility::LOG_USER,
8        hostname: None,
9        process: "myprogram".into(),
10        pid: 0,
11    };
12
13    match syslog_tls::unix(formatter) {
14        Err(e) => println!("impossible to connect to syslog: {:?}", e),
15        Ok(mut writer) => {
16            writer
17                .err("hello world")
18                .expect("could not write error message");
19            writer
20                .err("hello all".to_string())
21                .expect("could not write error message");
22        }
23    }
24}
More examples
Hide additional examples
examples/rfc5424.rs (lines 17-21)
5fn main() {
6    let formatter = Formatter5424 {
7        facility: Facility::LOG_USER,
8        hostname: None,
9        process: "myprogram".into(),
10        pid: 0,
11    };
12
13    match syslog_tls::unix(formatter) {
14        Err(e) => println!("impossible to connect to syslog: {:?}", e),
15        Ok(mut writer) => {
16            writer
17                .err(SyslogMessage {
18                    message_level: 1,
19                    structured: Vec::new(),
20                    message: "hello world".to_string(),
21                })
22                .expect("could not write error message");
23        }
24    }
25}
Source

pub fn warning<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn notice<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn info<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Source

pub fn debug<T>(&mut self, message: T) -> Result<()>
where F: LogFormat<T>,

Auto Trait Implementations§

§

impl<Backend, Formatter> Freeze for Logger<Backend, Formatter>
where Formatter: Freeze, Backend: Freeze,

§

impl<Backend, Formatter> RefUnwindSafe for Logger<Backend, Formatter>
where Formatter: RefUnwindSafe, Backend: RefUnwindSafe,

§

impl<Backend, Formatter> Send for Logger<Backend, Formatter>
where Formatter: Send, Backend: Send,

§

impl<Backend, Formatter> Sync for Logger<Backend, Formatter>
where Formatter: Sync, Backend: Sync,

§

impl<Backend, Formatter> Unpin for Logger<Backend, Formatter>
where Formatter: Unpin, Backend: Unpin,

§

impl<Backend, Formatter> UnwindSafe for Logger<Backend, Formatter>
where Formatter: UnwindSafe, Backend: 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.