1 /*
2  * Copyright (C) 2022 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 //! hilog dylib_crate for Rust.
17 use std::ffi::{c_char};
18 
19 #[macro_use]
20 mod macros;
21 
22 /// log level
23 #[derive(Debug)]
24 pub enum LogLevel {
25     /// min log level
26     LogLevelMin = 0,
27     /// The "debug" level.
28     ///
29     /// Designates lower priority log.
30     Debug = 3,
31     /// The "info" level.
32     ///
33     /// Designates useful information.
34     Info = 4,
35     /// The "warn" level.
36     ///
37     /// Designates hazardous situations.
38     Warn = 5,
39     /// The "error" level.
40     ///
41     /// Designates very serious errors.
42     Error = 6,
43     /// The "fatal" level.
44     ///
45     /// Designates major fatal anomaly.
46     Fatal = 7,
47     /// max log level
48     LogLevelMax,
49 }
50 
51 /// log type
52 #[derive(Debug)]
53 pub enum LogType {
54     /// log type for app log
55     LogApp = 0,
56     /// log type for init log
57     LogInit = 1,
58     /// log type for core log
59     LogCore = 3,
60     /// log type for kernel log
61     LogKmsg = 4,
62     /// max log type
63     LogTypeMax,
64 }
65 
66 /// hilog label
67 #[derive(Debug)]
68 pub struct HiLogLabel {
69     /// log type
70     pub log_type: LogType,
71     /// log domain
72     pub domain: u32,
73     /// log tag
74     pub tag: &'static str,
75 }
76 
77 // hilog ffi interface
78 extern "C" {
79     /// hilog ffi interface HiLogIsLoggabel
HiLogIsLoggable(domain: u32, tag: *const c_char, level: u32) -> bool80     pub fn HiLogIsLoggable(domain: u32, tag: *const c_char, level: u32) -> bool;
81     /// hilog ffi interface HiLogPrint
HiLogPrint( logType: u8, level: u8, domain: u32, tag: *const c_char, fmt: *const c_char, ... ) -> u3282     pub fn HiLogPrint(
83         logType: u8,
84         level: u8,
85         domain: u32,
86         tag: *const c_char,
87         fmt: *const c_char,
88         ...
89     ) -> u32;
90     /// hilog ffi interface IsPrivateSwitchOn
IsPrivateSwitchOn() -> bool91     pub fn IsPrivateSwitchOn() -> bool;
92     /// hilog ffi interface IsDebugOn
IsDebugOn() -> bool93     pub fn IsDebugOn() -> bool;
94 }
95