Struct Builder

Source
pub struct Builder { /* private fields */ }

Implementations§

Source§

impl Builder

Source

pub fn new() -> Builder

Source

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.

Source

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.

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 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);
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 info and above for logs globally:

use hilog::Builder;
use log::LevelFilter;

let mut builder = Builder::new();

builder.filter_level(LevelFilter::Info);
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 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);
Source

pub fn format<F>(&mut self, format: F) -> &mut Self
where F: Fn(&mut dyn Write, &Record<'_>) -> Result + Sync + Send + 'static,

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())
 });
Source

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.

Source

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.

Source

pub fn build(&mut self) -> Logger

Build an env logger.

The returned logger implements the Log trait and can be installed manually or nested within another logger.

Trait Implementations§

Source§

impl Default for Builder

Source§

fn default() -> Builder

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>,

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.