-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |