1 // Copyright (C) 2022 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 //! hilog dylib_crate for Rust. 15 use std::ffi::c_char; 16 17 #[macro_use] 18 mod macros; 19 20 /// log level 21 #[derive(Debug)] 22 pub enum LogLevel { 23 /// min log level 24 LogLevelMin = 0, 25 /// The "debug" level. 26 /// 27 /// Designates lower priority log. 28 Debug = 3, 29 /// The "info" level. 30 /// 31 /// Designates useful information. 32 Info = 4, 33 /// The "warn" level. 34 /// 35 /// Designates hazardous situations. 36 Warn = 5, 37 /// The "error" level. 38 /// 39 /// Designates very serious errors. 40 Error = 6, 41 /// The "fatal" level. 42 /// 43 /// Designates major fatal anomaly. 44 Fatal = 7, 45 /// max log level 46 LogLevelMax, 47 } 48 49 /// log type 50 #[derive(Debug)] 51 pub enum LogType { 52 /// log type for app log 53 LogApp = 0, 54 /// log type for init log 55 LogInit = 1, 56 /// log type for core log 57 LogCore = 3, 58 /// log type for kernel log 59 LogKmsg = 4, 60 /// max log type 61 LogTypeMax, 62 } 63 64 /// hilog label 65 #[derive(Debug)] 66 pub struct HiLogLabel { 67 /// log type 68 pub log_type: LogType, 69 /// log domain 70 pub domain: u32, 71 /// log tag 72 pub tag: &'static str, 73 } 74 75 // hilog ffi interface 76 extern "C" { 77 /// hilog ffi interface HiLogIsLoggabel HiLogIsLoggable(domain: u32, tag: *const c_char, level: u32) -> bool78 pub fn HiLogIsLoggable(domain: u32, tag: *const c_char, level: u32) -> bool; 79 /// hilog ffi interface HiLogPrint HiLogPrint( logType: u8, level: u8, domain: u32, tag: *const c_char, fmt: *const c_char, ... ) -> u3280 pub fn HiLogPrint( 81 logType: u8, 82 level: u8, 83 domain: u32, 84 tag: *const c_char, 85 fmt: *const c_char, 86 ... 87 ) -> u32; 88 /// hilog ffi interface IsPrivateSwitchOn IsPrivateSwitchOn() -> bool89 pub fn IsPrivateSwitchOn() -> bool; 90 /// hilog ffi interface IsDebugOn IsDebugOn() -> bool91 pub fn IsDebugOn() -> bool; 92 } 93