ohos-hilog-binding 0.1.2

hilog binding for rust
docs.rs failed to build ohos-hilog-binding-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

ohos-hilog-binding

Install

cargo add ohos-hilog-binding

Usage

use hilog_binding::hilog_debug;
use napi_derive_ohos::napi;

#[napi]
pub fn add(left: u32, right: u32) -> u32 {
    hilog_debug!("hello world");
    hilog_debug!(
        "test",
        LogOptions {
          tag: Some("testTag"),
          domain: None
      }
    );
    left + right
}

Feature

redirect

Allow us redirect stdout/stderr to hilog.

# Cargo.toml

[dependencies]
ohos-hilog-binding = {version = "*", features = ["redirect"]}
use napi_derive_ohos::napi;

#[napi]
pub fn add(left: u32, right: u32) -> u32 {
  // setup at first
  let _handle = ohos_hilog_binding::forward_stdio_to_hilog();
  // can be redirected to hilog with info level
  println!("hello");

  left + right
}


log

Allow us use log as log library.

For log trace level, we will convert to debug level which is not supported in OHOS.

# Cargo.toml

[dependencies]
ohos-hilog-binding = {version = "*", features = ["log"]}
log                = { version = "*" }
use napi_derive_ohos::napi;

use log::{debug, error, LevelFilter};
use ohos_hilog_binding::log::Config;

#[napi]
pub fn info() {
    ohos_hilog_binding::log::init_once(Config::default().with_max_level(LevelFilter::Info));

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