diff --git a/.vitepress/BasicSideBar.mts b/.vitepress/BasicSideBar.mts index 7f4f35d..6e07596 100644 --- a/.vitepress/BasicSideBar.mts +++ b/.vitepress/BasicSideBar.mts @@ -1,4 +1,6 @@ -export const BasicSideBar = [ +import {DefaultTheme} from "vitepress"; + +export const BasicSideBar: DefaultTheme.SidebarItem[] = [ { text: 'Basic', items: [ @@ -27,7 +29,12 @@ export const BasicSideBar = [ text: 'Ecosystem', collapsed: false, items: [ - {text: '@ohos-rs/crc32', link: "/docs/ecosystem/crc32"} + {text: '@ohos-rs/crc32', link: "/docs/ecosystem/crc32"}, + { + text: 'Native binding', items: [ + {text: 'hilog-binding', link: '/docs/ecosystem/native/hilog-binding'} + ] + } ] }, { diff --git a/src/docs/ecosystem/native/hilog-binding.md b/src/docs/ecosystem/native/hilog-binding.md new file mode 100644 index 0000000..12d1f4d --- /dev/null +++ b/src/docs/ecosystem/native/hilog-binding.md @@ -0,0 +1,70 @@ +--- +editLink: true +--- + +# hilog-binding + +This is a binding crate for HarmonyOS's `hilog`. + +## Install + +```shell +cargo add hilog-binding +``` + +## Usage + +```rust +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 +} +``` + +## Docs + +This crate provides some macro to log info. + +### Support method + +- `hilog_debug` +- `hilog_info` +- `hilog_warn` +- `hilog_error` +- `hilog_fatal` + +The macro is below here: + +```rust +#[macro_export] +macro_rules! hilog_info { + ($info: expr) => { + hilog_binding::info($info, None); + }; + ($info: expr,$option: expr) => { + hilog_binding::info($info, Some($option)); + }; +} + +#[derive(Default)] +pub struct LogOptions<'a> { + // domain default is 0x0000 + pub domain: Option, + /// tag default is hilog_rs + pub tag: Option<&'a str>, +} +``` + +- `info` should be `str` +- `option` should be `LogOptions` \ No newline at end of file