Struct JloggerBuilder

Source
pub struct JloggerBuilder<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> JloggerBuilder<'a>

Source

pub fn new() -> Self

Create a new JloggerBuilder which is used to build a Jlogger.

§Examples
    use jlogger_tracing::{JloggerBuilder, LogTimeFormat, LevelFilter};

    JloggerBuilder::new()
       .max_level(LevelFilter::DEBUG)
       .log_console(true)
       .log_time(LogTimeFormat::TimeStamp)
       .log_file(Some(("/tmp/my_log.log", false)))
       .build();
Source

pub fn max_level(self, max_level: LevelFilter) -> Self

Set the max level to be outputted. Log messages with a level below it will not be outputted. At runtime, the log level can be filtered though “JLOGGER_LEVEL” environment variable.

Source

pub fn log_console(self, log_console: bool) -> Self

If enabled, log message will be printed to the console. Default is true.

Source

pub fn log_file(self, log_file: Option<(&'a str, bool)>) -> Self

Log file name. If specified, log message will be outputted to it. A tuple (log_file: &str, append: bool) is used to specify the log file. if “append” is true and the log file already exists, the log message will be appended to the log file. Otherwise a new log file will be created.

Source

pub fn log_runtime(self, log_runtime: bool) -> Self

Add runtime information to log message. If the current thread name is set, it will be used as runtime information, otherwise process name is used

DEBUG thread1 : logging from thread thread1.
DEBUG jlogger-cac0970c6f073082 : logging from a thread whose name is not set.

Source

pub fn log_time(self, time_format: LogTimeFormat) -> Self

Time stamp string format, only take effect when time stamp is enable in the log.

  • TimeStamp
    Timestamp (from system boot) will be outputted in the log message.

9080.163365118 DEBUG test_debug_macro : src/lib.rs-364 : this is debug
9083.164066687 INFO test_debug_macro : this is info

  • TimeLocal
    Date and time are printed in the log message.

2022-05-17 13:00:03 DEBUG : src/lib.rs-363 : this is debug
2022-05-17 13:00:06 INFO : this is info

  • TimeNone No timestamp included in the log message.
Source

pub fn tracing_span_event(self, span: FmtSpan) -> Self

Enable tracing span event. See tracing_subscriber::fmt::format::FmtSpan for detail This only take affect when tracing::Span is used.

Source

pub fn build(self)

Build a Jlogger.

Trait Implementations§

Source§

impl<'a> Default for JloggerBuilder<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JloggerBuilder<'a>

§

impl<'a> RefUnwindSafe for JloggerBuilder<'a>

§

impl<'a> Send for JloggerBuilder<'a>

§

impl<'a> Sync for JloggerBuilder<'a>

§

impl<'a> Unpin for JloggerBuilder<'a>

§

impl<'a> UnwindSafe for JloggerBuilder<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more