pub struct LoggerBuilder { /* private fields */ }
logger
only.Implementations§
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn fmt_level(level: &Level) -> String
pub fn fmt_level(level: &Level) -> String
Return colored string of level
.
- TRACE/DEBUG => Magenta
- INFO => Green
- WARN => Yellow
- ERROR => Red
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new logger instance. Default is colorful writer, INFO level, no filename and line number.
Sourcepub fn json_writer(self, writer: WriterFn) -> Self
pub fn json_writer(self, writer: WriterFn) -> Self
Sourcepub fn color_writer(self, writer: WriterFn) -> Self
pub fn color_writer(self, writer: WriterFn) -> Self
Sourcepub fn line_number(self) -> Self
pub fn line_number(self) -> Self
Enable line number in the log.
Sourcepub fn handler<F>(self, handler: F) -> Self
pub fn handler<F>(self, handler: F) -> Self
Customize the handler.
The customized handler will be invoked first, even before the filter. When the return value is false, further handler will be skipped. Otherwise, normal log hander will still be invoked.
§Warning
Do not perform heavy workloads, it can block other logs!
Sourcepub fn filter<F>(self, filter: F) -> Self
pub fn filter<F>(self, filter: F) -> Self
Customize the filter. Filter out unwanted logs.
When the filter function return false, no logs will be sent to the transformer.
§Warning
Do not perform heavy workloads, it can block other logs!
Sourcepub fn transformer<F>(self, transformer: F) -> Self
pub fn transformer<F>(self, transformer: F) -> Self
Customize the transformer. Change the logs on the fly.
After this function, LogItem will be sent to the corresponding writer.
§Warning
Do not perform heavy workloads, it can block other logs!
Sourcepub fn start(self) -> (Logger, LoggerGuard)
pub fn start(self) -> (Logger, LoggerGuard)
Start logger. This method will spawn a new thread to print the log.
You should call this method only once for the entire program. For FFI library, you need to call this method once in the library code and keep the return values alive. Then customize the Self::handler and send output back to the main program.
Auto Trait Implementations§
impl Freeze for LoggerBuilder
impl !RefUnwindSafe for LoggerBuilder
impl Send for LoggerBuilder
impl !Sync for LoggerBuilder
impl Unpin for LoggerBuilder
impl !UnwindSafe for LoggerBuilder
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more