pub struct Builder { /* private fields */ }
Implementations§
Source§impl Builder
impl Builder
pub fn new() -> Builder
Sourcepub fn set_domain(&mut self, domain: LogDomain) -> &mut Self
pub fn set_domain(&mut self, domain: LogDomain) -> &mut Self
Sets the Service domain for the logs
Users can set a custom domain, which allows filtering by hilogd.
Sourcepub fn set_tag(&mut self, tag: &str) -> &mut Self
pub fn set_tag(&mut self, tag: &str) -> &mut Self
Sets the tag for the logs. Maximum length is 31 bytes.
If not set, the module path will be used as the tag. If the provided tag is longer than 31 bytes it will be truncated.
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 info and above for logs in path::to::module
:
use hilog::Builder;
use log::LevelFilter;
let mut builder = Builder::new();
builder.filter_module("path::to::module", LevelFilter::Info);
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 info and above for logs globally:
use hilog::Builder;
use log::LevelFilter;
let mut builder = Builder::new();
builder.filter_level(LevelFilter::Info);
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 info and above for logs in path::to::module
:
use hilog::Builder;
use log::LevelFilter;
let mut builder = Builder::new();
builder.filter(Some("path::to::module"), LevelFilter::Info);
Sourcepub fn format<F>(&mut self, format: F) -> &mut Self
pub fn format<F>(&mut self, format: F) -> &mut Self
Adds a custom format function to the logger.
The format function will be called for each log message that would be output. It should write the formatted log message to the provided writer.
§Examples
use hilog::Builder;
use log::{Record, Level};
let mut builder = Builder::new();
builder.format(|buf, record| {
writeln!(buf, "{}:{} - {}",
record.file().unwrap_or("unknown"),
record.line().unwrap_or(0),
record.args())
});
Sourcepub fn try_init(&mut self) -> Result<(), SetLoggerError>
pub fn try_init(&mut self) -> Result<(), SetLoggerError>
Initializes the global logger with the built env 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)
pub fn init(&mut self)
Initializes the global logger with the built env 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.