1 /* 2 * Copyright (c) 2021 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 #ifndef HIVIEWDFX_HILOG_CPP_H 17 #define HIVIEWDFX_HILOG_CPP_H 18 19 #include "hilog/log_c.h" 20 21 #ifdef __cplusplus 22 namespace OHOS { 23 namespace HiviewDFX { 24 /** 25 * @brief Initialize log parameters: type, domain and tag. 26 * domain: Indicates the log service domainID. Different LogType have different domainID ranges, 27 * Log type of LOG_APP: 0-0xFFFF, 28 * Log type of LOG_CORE & LOG_INIT: 0xD000000-0xD0FFFFF. 29 * tag: Indicates the log service tag, you can customize the tag as needed, usually the keyword of the module. 30 */ 31 using HiLogLabel = struct { 32 LogType type; 33 unsigned int domain; 34 const char *tag; 35 }; 36 37 38 class HiLog final { 39 public: 40 /** 41 * @brief Hilog C++ class interface of different log level. 42 * Debug: Designates lower priority log. 43 * Info: Designates useful information. 44 * Warn: Designates hazardous situations. 45 * Error: Designates very serious errors. 46 * Fatal: Designates major fatal anomaly. 47 * 48 * @param label HiLogLabel for the log 49 * @param fmt Format string for the log 50 */ 51 static int Debug(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); 52 static int Info(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); 53 static int Warn(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); 54 static int Error(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); 55 static int Fatal(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); 56 }; 57 } // namespace HiviewDFX 58 } // namespace OHOS 59 60 /** 61 * @brief Hilog C++ macro interface of different log level. 62 * HiLogDebug: Designates lower priority log. 63 * HiLogInfo: Designates useful information. 64 * HiLogWarn: Designates hazardous situations. 65 * HiLogError: Designates very serious errors. 66 * HiLogFatal: Designates major fatal anomaly. 67 * 68 * @param label HiLogLabel for the log 69 * @param fmt Format string for the log 70 */ 71 #define HiLogDebug(label, fmt, ...) HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, fmt, ##__VA_ARGS__) 72 #define HiLogInfo(label, fmt, ...) HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, fmt, ##__VA_ARGS__) 73 #define HiLogWarn(label, fmt, ...) HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, fmt, ##__VA_ARGS__) 74 #define HiLogError(label, fmt, ...) HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, fmt, ##__VA_ARGS__) 75 #define HiLogFatal(label, fmt, ...) HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, fmt, ##__VA_ARGS__) 76 77 #endif // __cplusplus 78 #endif // HIVIEWDFX_HILOG_CPP_H 79