Skip to content

Commit

Permalink
feat: add native binding
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Mar 7, 2024
1 parent 342de07 commit 88b02a2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
11 changes: 9 additions & 2 deletions .vitepress/BasicSideBar.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const BasicSideBar = [
import {DefaultTheme} from "vitepress";

export const BasicSideBar: DefaultTheme.SidebarItem[] = [
{
text: 'Basic',
items: [
Expand Down Expand Up @@ -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'}
]
}
]
},
{
Expand Down
70 changes: 70 additions & 0 deletions src/docs/ecosystem/native/hilog-binding.md
Original file line number Diff line number Diff line change
@@ -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<u32>,
/// tag default is hilog_rs
pub tag: Option<&'a str>,
}
```

- `info` should be `str`
- `option` should be `LogOptions`

0 comments on commit 88b02a2

Please sign in to comment.