1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! This module defines the macros required for log printing.
17
18 use std::ffi::{c_char, CString};
19
20 use hilog_rust::hilog;
21
22 /// the function to print log, and may be should not be used instead of logi
log_func_i(log: &str)23 pub fn log_func_i(log: &str) {
24 let log_label = hilog_rust::HiLogLabel { log_type: hilog_rust::LogType::LogCore, domain: 0xD002F08, tag: "Asset" };
25 hilog_rust::info!(log_label, "{}", @public(log));
26 }
27
28 /// the function to print log, and may be should not be used instead of logw
log_func_w(log: &str)29 pub fn log_func_w(log: &str) {
30 let log_label = hilog_rust::HiLogLabel { log_type: hilog_rust::LogType::LogCore, domain: 0xD002F08, tag: "Asset" };
31 hilog_rust::warn!(log_label, "{}", @public(log));
32 }
33
34 /// the function to print log, and may be should not be used instead of loge
log_func_e(log: &str)35 pub fn log_func_e(log: &str) {
36 let log_label = hilog_rust::HiLogLabel { log_type: hilog_rust::LogType::LogCore, domain: 0xD002F08, tag: "Asset" };
37 hilog_rust::error!(log_label, "{}", @public(log));
38 }
39
40 /// Print logs at the info level.
41 ///
42 /// # Examples
43 ///
44 /// ```
45 /// logi!("hello, {}", "world");
46 /// ```
47 #[macro_export]
48 macro_rules! logi {
49 ($($arg:tt)*) => (
50 $crate::log_func_i(&format!($($arg)*));
51 );
52 }
53
54 /// Print logs at the info level.
55 ///
56 /// # Examples
57 ///
58 /// ```
59 /// logw!("hello, {}", "world");
60 /// ```
61 #[macro_export]
62 macro_rules! logw {
63 ($($arg:tt)*) => (
64 $crate::log_func_w(&format!($($arg)*));
65 );
66 }
67
68 /// Print logs at the error level.
69 ///
70 /// # Examples
71 ///
72 /// ```
73 /// loge!("Error message: {}", "read file failed");
74 /// ```
75 #[macro_export]
76 macro_rules! loge {
77 ($($arg:tt)*) => (
78 $crate::log_func_e(&format!($($arg)*));
79 );
80 }
81