Crate ohos_hilog

Source
Expand description

A logger which writes to ohos output.

§Example

#[macro_use] extern crate log;
extern crate ohos_hilog;

use log::LevelFilter;
use ohos_hilog::Config;

/// Ohos code may not have obvious "main", this is just an example.
fn main() {
    ohos_hilog::init_once(
        Config::default().with_max_level(LevelFilter::Trace),
    );

    debug!("this is a debug {}", "message");
    error!("this is printed by default");
}

§Example with module path filter

It is possible to limit log messages to output from a specific crate, and override the logcat tag name (by default, the crate name is used):

#[macro_use] extern crate log;
extern crate ohos_hilog;

use log::LevelFilter;
use ohos_hilog::{Config,FilterBuilder};

fn main() {
    ohos_hilog::init_once(
        Config::default()
            .with_max_level(LevelFilter::Trace)
            .with_tag("mytag")
            .with_filter(FilterBuilder::new().parse("debug,hello::crate=trace").build()),
    );

    // ..
}

§Example with a custom log formatter

use ohos_hilog::Config;

ohos_hilog::init_once(
    Config::default()
        .with_max_level(log::LevelFilter::Trace)
        .format(|f, record| write!(f, "my_app: {}", record.args()))
)

Structs§

Functions§

  • Initializes the global logger with an ohos logger.
  • Send a log record to Ohos logging backend.