Function init

Source
pub fn init(is_critical: bool) -> Result<()>
Expand description

Initializes the DLog logging system.

This function sets up the logging infrastructure by configuring the logger for the current application. It should be called once.

Under the hood, there is a struct with Log trait implemented that uses dlog_print for sending logs to DLog. If invoked with is_critical = true, it sends critical logs instead.

Priority of a log is defined by a macro used and tag is constructed from the binary name. However, it can be overwritten - see example below.

§Errors

§Examples

Sending non-critical logs:

use log::info;

fn main() -> Result<(), std::io::Error> {
    dlog::init(false)?;
    info!("my first log");
}

Sending critical logs:

use log::info;

fn main() -> Result<(), std::io::Error> {
    dlog::init(true)?;
    info!("my first critical log");
}

You can set your custom tag by setting target argument:

use log::info;

fn main() -> Result<(), std::io::Error> {
    dlog::init(false)?;
    info!(target: "my_tag", "my first log with a custom tag");
}