pub struct Builder { /* private fields */ }
Expand description

Builder for initializing logger

The builder is used to initialize the logging framework for later use. It provides

Implementations§

source§

impl Builder

source

pub fn new() -> Builder

Initializes the log builder with defaults.

§Examples

Create a new builder and configure filters and style:


let mut builder = Builder::new();
builder.filter(None, LevelFilter::Info).init();
source

pub fn buffer(&mut self, buffer: Buffer) -> &mut Self

Use a specific android log buffer. Defaults to the main buffer is used as tag (if present).

§Examples

let mut builder = Builder::new();
builder.buffer(Buffer::Crash)
    .init();
source

pub fn tag(&mut self, tag: &str) -> &mut Self

Use a specific log tag. If no tag is set the module path is used as tag (if present).

§Examples

let mut builder = Builder::new();

builder.tag("foo")
    .init();
source

pub fn tag_target(&mut self) -> &mut Self

Use the target string as tag

§Examples

let mut builder = Builder::new();
builder.tag_target().init();
source

pub fn tag_target_strip(&mut self) -> &mut Self

Use the target string as tag and strip off ::.*

§Examples

let mut builder = Builder::new();
builder.tag_target_strip().init();
source

pub fn prepend_module(&mut self, prepend_module: bool) -> &mut Self

Prepend module to log message.

If set true the Rust module path is prepended to the log message.

§Examples

let mut builder = Builder::new();
builder.prepend_module(true).init();
source

pub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self

Adds a directive to the filter for a specific module.

§Examples

Only include messages for warning and above for logs in path::to::module:


let mut builder = Builder::new();

builder.filter_module("path::to::module", LevelFilter::Info).init();
source

pub fn filter_level(&mut self, level: LevelFilter) -> &mut Self

Adds a directive to the filter for all modules.

§Examples

Only include messages for warning and above.


let mut builder = Builder::new();
builder.filter_level(LevelFilter::Info).init();
source

pub fn filter(&mut self, module: Option<&str>, level: LevelFilter) -> &mut Self

Adds filters to the logger.

The given module (if any) will log at most the specified level provided. If no module is provided then the filter will apply to all log messages.

§Examples

Only include messages for warning and above for logs in path::to::module:


let mut builder = Builder::new();
builder.filter(Some("path::to::module"), LevelFilter::Info).init();
source

pub fn parse_filters(&mut self, filters: &str) -> &mut Self

Parses the directives string in the same form as the RUST_LOG environment variable.

See the module documentation for more details.

source

pub fn try_init(&mut self) -> Result<Logger, SetLoggerError>

Initializes the global logger with the built logd logger.

This should be called early in the execution of a Rust program. Any log events that occur before initialization will be ignored.

§Errors

This function will fail if it is called more than once, or if another library has already initialized a global logger.

source

pub fn init(&mut self) -> Logger

Initializes the global logger with the built logger.

This should be called early in the execution of a Rust program. Any log events that occur before initialization will be ignored.

§Panics

This function will panic if it is called more than once, or if another library has already initialized a global logger.

Trait Implementations§

source§

impl Default for Builder

source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, U> TryFrom<U> for T
where 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 T
where 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.