pub struct DispatchBuilder<const APPEND: bool> { /* private fields */ }
Expand description
A builder for configuring a log dispatch, including filters and appenders.
§Examples
use logforth::append;
logforth::builder()
.dispatch(|d| {
d.filter(log::LevelFilter::Info)
.append(append::Stdout::default())
})
.apply();
Implementations§
Source§impl DispatchBuilder<false>
impl DispatchBuilder<false>
Sourcepub fn filter(self, filter: impl Into<Box<dyn Filter>>) -> Self
pub fn filter(self, filter: impl Into<Box<dyn Filter>>) -> Self
Add a filter to this dispatch.
§Examples
use logforth::append;
logforth::builder()
.dispatch(|d| {
d.filter(log::LevelFilter::Error)
.append(append::Stderr::default())
})
.apply();
Examples found in repository?
examples/custom_layout_filter.rs (line 48)
45fn main() {
46 logforth::builder()
47 .dispatch(|d| {
48 d.filter(CustomFilter)
49 .append(append::Stdout::default().with_layout(CustomLayout))
50 })
51 .apply();
52
53 log::error!("Hello error!");
54 log::warn!("Hello warn!");
55 log::info!("Hello info!");
56 log::debug!("Hello debug!");
57 log::trace!("Hello trace!");
58}
More examples
examples/multiple_dispatches.rs (line 21)
18fn main() {
19 logforth::builder()
20 .dispatch(|d| {
21 d.filter(LevelFilter::Error)
22 .append(append::Stderr::default())
23 })
24 .dispatch(|d| {
25 d.filter(LevelFilter::Info)
26 .append(append::Stdout::default())
27 })
28 .apply();
29
30 log::error!("Hello error!");
31 log::warn!("Hello warn!");
32 log::info!("Hello info!");
33 log::debug!("Hello debug!");
34 log::trace!("Hello trace!");
35}
examples/syslog.rs (line 21)
17fn main() {
18 let (append, _guard) = SyslogBuilder::tcp_well_known().unwrap().build();
19
20 logforth::builder()
21 .dispatch(|d| d.filter(log::LevelFilter::Trace).append(append))
22 .apply();
23
24 let repeat = 1;
25
26 for i in 0..repeat {
27 log::error!("Hello syslog error!");
28 log::warn!("Hello syslog warn!");
29 log::info!("Hello syslog info!");
30 log::debug!("Hello syslog debug!");
31 log::trace!("Hello syslog trace!");
32
33 if i + 1 < repeat {
34 std::thread::sleep(std::time::Duration::from_secs(10));
35 }
36 }
37}
examples/single_file.rs (line 25)
18fn main() {
19 let (single_writer, _guard) = SingleFileBuilder::new("my.log")
20 .layout(JsonLayout::default())
21 .build()
22 .unwrap();
23
24 logforth::builder()
25 .dispatch(|d| d.filter(log::LevelFilter::Trace).append(single_writer))
26 .apply();
27
28 let repeat = 1;
29
30 for i in 0..repeat {
31 log::error!("Hello error!");
32 log::warn!("Hello warn!");
33 log::info!("Hello info!");
34 log::debug!("Hello debug!");
35 log::trace!("Hello trace!");
36
37 if i + 1 < repeat {
38 std::thread::sleep(std::time::Duration::from_secs(10));
39 }
40 }
41}
examples/rolling_file.rs (line 28)
19fn main() {
20 let (rolling_writer, _guard) = RollingFileBuilder::new("logs")
21 .layout(JsonLayout::default())
22 .rotation(Rotation::Daily)
23 .filename_prefix("app_log")
24 .build()
25 .unwrap();
26
27 logforth::builder()
28 .dispatch(|d| d.filter(log::LevelFilter::Trace).append(rolling_writer))
29 .apply();
30
31 let repeat = 1;
32
33 for i in 0..repeat {
34 log::error!("Hello error!");
35 log::warn!("Hello warn!");
36 log::info!("Hello info!");
37 log::debug!("Hello debug!");
38 log::trace!("Hello trace!");
39
40 if i + 1 < repeat {
41 std::thread::sleep(std::time::Duration::from_secs(10));
42 }
43 }
44}
Sourcepub fn diagnostic(self, diagnostic: impl Into<Box<dyn Diagnostic>>) -> Self
pub fn diagnostic(self, diagnostic: impl Into<Box<dyn Diagnostic>>) -> Self
Add a diagnostic to this dispatch.
§Examples
use logforth::append;
use logforth::diagnostic;
logforth::builder()
.dispatch(|d| {
d.filter(log::LevelFilter::Error)
.diagnostic(diagnostic::ThreadLocalDiagnostic::default())
.append(append::Stderr::default())
})
.apply();
Source§impl<const APPEND: bool> DispatchBuilder<APPEND>
impl<const APPEND: bool> DispatchBuilder<APPEND>
Sourcepub fn append(self, append: impl Into<Box<dyn Append>>) -> DispatchBuilder<true>
pub fn append(self, append: impl Into<Box<dyn Append>>) -> DispatchBuilder<true>
Add an appender to this dispatch.
§Examples
use logforth::append;
logforth::builder()
.dispatch(|d| d.append(append::Stdout::default()))
.apply();
Examples found in repository?
More examples
examples/custom_layout_filter.rs (line 49)
45fn main() {
46 logforth::builder()
47 .dispatch(|d| {
48 d.filter(CustomFilter)
49 .append(append::Stdout::default().with_layout(CustomLayout))
50 })
51 .apply();
52
53 log::error!("Hello error!");
54 log::warn!("Hello warn!");
55 log::info!("Hello info!");
56 log::debug!("Hello debug!");
57 log::trace!("Hello trace!");
58}
examples/journald.rs (line 20)
16fn main() {
17 use logforth::append::Journald;
18
19 let append = Journald::new().unwrap();
20 logforth::builder().dispatch(|d| d.append(append)).apply();
21
22 log::error!("Hello, journald at ERROR!");
23 log::warn!("Hello, journald at WARN!");
24 log::info!("Hello, journald at INFO!");
25 log::debug!("Hello, journald at DEBUG!");
26 log::trace!("Hello, journald at TRACE!");
27}
examples/multiple_dispatches.rs (line 22)
18fn main() {
19 logforth::builder()
20 .dispatch(|d| {
21 d.filter(LevelFilter::Error)
22 .append(append::Stderr::default())
23 })
24 .dispatch(|d| {
25 d.filter(LevelFilter::Info)
26 .append(append::Stdout::default())
27 })
28 .apply();
29
30 log::error!("Hello error!");
31 log::warn!("Hello warn!");
32 log::info!("Hello info!");
33 log::debug!("Hello debug!");
34 log::trace!("Hello trace!");
35}
examples/syslog.rs (line 21)
17fn main() {
18 let (append, _guard) = SyslogBuilder::tcp_well_known().unwrap().build();
19
20 logforth::builder()
21 .dispatch(|d| d.filter(log::LevelFilter::Trace).append(append))
22 .apply();
23
24 let repeat = 1;
25
26 for i in 0..repeat {
27 log::error!("Hello syslog error!");
28 log::warn!("Hello syslog warn!");
29 log::info!("Hello syslog info!");
30 log::debug!("Hello syslog debug!");
31 log::trace!("Hello syslog trace!");
32
33 if i + 1 < repeat {
34 std::thread::sleep(std::time::Duration::from_secs(10));
35 }
36 }
37}
examples/single_file.rs (line 25)
18fn main() {
19 let (single_writer, _guard) = SingleFileBuilder::new("my.log")
20 .layout(JsonLayout::default())
21 .build()
22 .unwrap();
23
24 logforth::builder()
25 .dispatch(|d| d.filter(log::LevelFilter::Trace).append(single_writer))
26 .apply();
27
28 let repeat = 1;
29
30 for i in 0..repeat {
31 log::error!("Hello error!");
32 log::warn!("Hello warn!");
33 log::info!("Hello info!");
34 log::debug!("Hello debug!");
35 log::trace!("Hello trace!");
36
37 if i + 1 < repeat {
38 std::thread::sleep(std::time::Duration::from_secs(10));
39 }
40 }
41}
Additional examples can be found in:
Trait Implementations§
Auto Trait Implementations§
impl<const APPEND: bool> Freeze for DispatchBuilder<APPEND>
impl<const APPEND: bool> !RefUnwindSafe for DispatchBuilder<APPEND>
impl<const APPEND: bool> Send for DispatchBuilder<APPEND>
impl<const APPEND: bool> Sync for DispatchBuilder<APPEND>
impl<const APPEND: bool> Unpin for DispatchBuilder<APPEND>
impl<const APPEND: bool> !UnwindSafe for DispatchBuilder<APPEND>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request