Struct android_logd_logger::Builder
source · 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
impl Builder
sourcepub fn new() -> Builder
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();
sourcepub fn buffer(&mut self, buffer: Buffer) -> &mut Self
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();
sourcepub fn tag(&mut self, tag: &str) -> &mut Self
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();
sourcepub fn tag_target(&mut self) -> &mut Self
pub fn tag_target(&mut self) -> &mut Self
Use the target string as tag
§Examples
let mut builder = Builder::new();
builder.tag_target().init();
sourcepub fn tag_target_strip(&mut self) -> &mut Self
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();
sourcepub fn prepend_module(&mut self, prepend_module: bool) -> &mut Self
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();
sourcepub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self
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();
sourcepub fn filter_level(&mut self, level: LevelFilter) -> &mut Self
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();
sourcepub fn filter(&mut self, module: Option<&str>, level: LevelFilter) -> &mut Self
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();
sourcepub fn parse_filters(&mut self, filters: &str) -> &mut Self
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.
sourcepub fn try_init(&mut self) -> Result<Logger, SetLoggerError>
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.
sourcepub fn init(&mut self) -> Logger
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.