Skip to main content

LoggingClientBuilder

Struct LoggingClientBuilder 

Source
pub struct LoggingClientBuilder { /* private fields */ }

Implementations§

Source§

impl LoggingClientBuilder

Source

pub fn new(socket: impl Into<String>) -> Self

Source

pub fn auth_token(self, token: impl Into<String>) -> Self

Examples found in repository?
examples/logging.rs (line 19)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let socket = env::var("FALCORN_LOG_SOCKET").unwrap_or_else(|_| DEFAULT_LOG_SOCKET.to_string());
10    let token = env::var("FALCORN_LOG_TOKEN").ok();
11    let client_name = env::var("FALCORN_LOG_CLIENT").ok();
12    let filter = env::var("FALCORN_LOG_FILTER")
13        .ok()
14        .and_then(|value| value.parse::<u8>().ok())
15        .unwrap_or(PLUGIN_FILTER_ALL);
16
17    let mut builder = LoggingClient::builder(socket);
18    if let Some(token) = token {
19        builder = builder.auth_token(token);
20    }
21    if let Some(client_name) = client_name {
22        builder = builder.client_name(client_name);
23    }
24    builder = builder.filter_mask(filter);
25
26    let mut client = builder.connect()?;
27    println!(
28        "Connected. Filters: log={} access={} metrics={} (mask={:#04x})",
29        filter & PLUGIN_FILTER_LOG_MESSAGE != 0,
30        filter & PLUGIN_FILTER_ACCESS_LOG != 0,
31        filter & PLUGIN_FILTER_METRICS != 0,
32        filter
33    );
34
35    loop {
36        let event = client.next_event()?;
37        match event {
38            falcorn_sdk::proto::logging::PluginEvent::LogMessage {
39                ts_millis,
40                level,
41                pid,
42                worker_id,
43                message,
44            } => {
45                println!(
46                    "[{}] {} pid={} worker={:?} - {}",
47                    ts_millis,
48                    level.as_str(),
49                    pid,
50                    worker_id,
51                    message
52                );
53            }
54            falcorn_sdk::proto::logging::PluginEvent::AccessLog {
55                ts_millis,
56                remote,
57                method,
58                uri,
59                status,
60                duration_micros,
61                ..
62            } => {
63                println!(
64                    "[{}] {} {} {} status={} {}us",
65                    ts_millis, remote, method, uri, status, duration_micros
66                );
67            }
68            falcorn_sdk::proto::logging::PluginEvent::Metrics(metrics) => {
69                println!(
70                    "METRICS rps={:.2} success_rate={:.4} avg_us={} active_conn={}",
71                    metrics.requests_per_second,
72                    metrics.success_rate,
73                    metrics.avg_response_time_micros,
74                    metrics.active_connections
75                );
76            }
77        }
78    }
79}
Source

pub fn client_name(self, name: impl Into<String>) -> Self

Examples found in repository?
examples/logging.rs (line 22)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let socket = env::var("FALCORN_LOG_SOCKET").unwrap_or_else(|_| DEFAULT_LOG_SOCKET.to_string());
10    let token = env::var("FALCORN_LOG_TOKEN").ok();
11    let client_name = env::var("FALCORN_LOG_CLIENT").ok();
12    let filter = env::var("FALCORN_LOG_FILTER")
13        .ok()
14        .and_then(|value| value.parse::<u8>().ok())
15        .unwrap_or(PLUGIN_FILTER_ALL);
16
17    let mut builder = LoggingClient::builder(socket);
18    if let Some(token) = token {
19        builder = builder.auth_token(token);
20    }
21    if let Some(client_name) = client_name {
22        builder = builder.client_name(client_name);
23    }
24    builder = builder.filter_mask(filter);
25
26    let mut client = builder.connect()?;
27    println!(
28        "Connected. Filters: log={} access={} metrics={} (mask={:#04x})",
29        filter & PLUGIN_FILTER_LOG_MESSAGE != 0,
30        filter & PLUGIN_FILTER_ACCESS_LOG != 0,
31        filter & PLUGIN_FILTER_METRICS != 0,
32        filter
33    );
34
35    loop {
36        let event = client.next_event()?;
37        match event {
38            falcorn_sdk::proto::logging::PluginEvent::LogMessage {
39                ts_millis,
40                level,
41                pid,
42                worker_id,
43                message,
44            } => {
45                println!(
46                    "[{}] {} pid={} worker={:?} - {}",
47                    ts_millis,
48                    level.as_str(),
49                    pid,
50                    worker_id,
51                    message
52                );
53            }
54            falcorn_sdk::proto::logging::PluginEvent::AccessLog {
55                ts_millis,
56                remote,
57                method,
58                uri,
59                status,
60                duration_micros,
61                ..
62            } => {
63                println!(
64                    "[{}] {} {} {} status={} {}us",
65                    ts_millis, remote, method, uri, status, duration_micros
66                );
67            }
68            falcorn_sdk::proto::logging::PluginEvent::Metrics(metrics) => {
69                println!(
70                    "METRICS rps={:.2} success_rate={:.4} avg_us={} active_conn={}",
71                    metrics.requests_per_second,
72                    metrics.success_rate,
73                    metrics.avg_response_time_micros,
74                    metrics.active_connections
75                );
76            }
77        }
78    }
79}
Source

pub fn filter_mask(self, mask: u8) -> Self

Examples found in repository?
examples/logging.rs (line 24)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let socket = env::var("FALCORN_LOG_SOCKET").unwrap_or_else(|_| DEFAULT_LOG_SOCKET.to_string());
10    let token = env::var("FALCORN_LOG_TOKEN").ok();
11    let client_name = env::var("FALCORN_LOG_CLIENT").ok();
12    let filter = env::var("FALCORN_LOG_FILTER")
13        .ok()
14        .and_then(|value| value.parse::<u8>().ok())
15        .unwrap_or(PLUGIN_FILTER_ALL);
16
17    let mut builder = LoggingClient::builder(socket);
18    if let Some(token) = token {
19        builder = builder.auth_token(token);
20    }
21    if let Some(client_name) = client_name {
22        builder = builder.client_name(client_name);
23    }
24    builder = builder.filter_mask(filter);
25
26    let mut client = builder.connect()?;
27    println!(
28        "Connected. Filters: log={} access={} metrics={} (mask={:#04x})",
29        filter & PLUGIN_FILTER_LOG_MESSAGE != 0,
30        filter & PLUGIN_FILTER_ACCESS_LOG != 0,
31        filter & PLUGIN_FILTER_METRICS != 0,
32        filter
33    );
34
35    loop {
36        let event = client.next_event()?;
37        match event {
38            falcorn_sdk::proto::logging::PluginEvent::LogMessage {
39                ts_millis,
40                level,
41                pid,
42                worker_id,
43                message,
44            } => {
45                println!(
46                    "[{}] {} pid={} worker={:?} - {}",
47                    ts_millis,
48                    level.as_str(),
49                    pid,
50                    worker_id,
51                    message
52                );
53            }
54            falcorn_sdk::proto::logging::PluginEvent::AccessLog {
55                ts_millis,
56                remote,
57                method,
58                uri,
59                status,
60                duration_micros,
61                ..
62            } => {
63                println!(
64                    "[{}] {} {} {} status={} {}us",
65                    ts_millis, remote, method, uri, status, duration_micros
66                );
67            }
68            falcorn_sdk::proto::logging::PluginEvent::Metrics(metrics) => {
69                println!(
70                    "METRICS rps={:.2} success_rate={:.4} avg_us={} active_conn={}",
71                    metrics.requests_per_second,
72                    metrics.success_rate,
73                    metrics.avg_response_time_micros,
74                    metrics.active_connections
75                );
76            }
77        }
78    }
79}
Source

pub fn read_timeout(self, timeout: Duration) -> Self

Source

pub fn write_timeout(self, timeout: Duration) -> Self

Source

pub fn connect(self) -> Result<LoggingClient>

Examples found in repository?
examples/logging.rs (line 26)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let socket = env::var("FALCORN_LOG_SOCKET").unwrap_or_else(|_| DEFAULT_LOG_SOCKET.to_string());
10    let token = env::var("FALCORN_LOG_TOKEN").ok();
11    let client_name = env::var("FALCORN_LOG_CLIENT").ok();
12    let filter = env::var("FALCORN_LOG_FILTER")
13        .ok()
14        .and_then(|value| value.parse::<u8>().ok())
15        .unwrap_or(PLUGIN_FILTER_ALL);
16
17    let mut builder = LoggingClient::builder(socket);
18    if let Some(token) = token {
19        builder = builder.auth_token(token);
20    }
21    if let Some(client_name) = client_name {
22        builder = builder.client_name(client_name);
23    }
24    builder = builder.filter_mask(filter);
25
26    let mut client = builder.connect()?;
27    println!(
28        "Connected. Filters: log={} access={} metrics={} (mask={:#04x})",
29        filter & PLUGIN_FILTER_LOG_MESSAGE != 0,
30        filter & PLUGIN_FILTER_ACCESS_LOG != 0,
31        filter & PLUGIN_FILTER_METRICS != 0,
32        filter
33    );
34
35    loop {
36        let event = client.next_event()?;
37        match event {
38            falcorn_sdk::proto::logging::PluginEvent::LogMessage {
39                ts_millis,
40                level,
41                pid,
42                worker_id,
43                message,
44            } => {
45                println!(
46                    "[{}] {} pid={} worker={:?} - {}",
47                    ts_millis,
48                    level.as_str(),
49                    pid,
50                    worker_id,
51                    message
52                );
53            }
54            falcorn_sdk::proto::logging::PluginEvent::AccessLog {
55                ts_millis,
56                remote,
57                method,
58                uri,
59                status,
60                duration_micros,
61                ..
62            } => {
63                println!(
64                    "[{}] {} {} {} status={} {}us",
65                    ts_millis, remote, method, uri, status, duration_micros
66                );
67            }
68            falcorn_sdk::proto::logging::PluginEvent::Metrics(metrics) => {
69                println!(
70                    "METRICS rps={:.2} success_rate={:.4} avg_us={} active_conn={}",
71                    metrics.requests_per_second,
72                    metrics.success_rate,
73                    metrics.avg_response_time_micros,
74                    metrics.active_connections
75                );
76            }
77        }
78    }
79}

Trait Implementations§

Source§

impl Clone for LoggingClientBuilder

Source§

fn clone(&self) -> LoggingClientBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LoggingClientBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.