Struct syslog_tls::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)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let formatter = Formatter3164 {
        facility: Facility::LOG_USER,
        hostname: None,
        process: "myprogram".into(),
        pid: 0,
    };

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

    match syslog_tls::unix(formatter) {
        Err(e) => println!("impossible to connect to syslog: {:?}", e),
        Ok(mut writer) => {
            writer
                .err(SyslogMessage {
                    message_level: 1,
                    structured: Vec::new(),
                    message: "hello world".to_string(),
                })
                .expect("could not write error message");
        }
    }
}
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> RefUnwindSafe for Logger<Backend, Formatter>where Backend: RefUnwindSafe, Formatter: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.