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 #ifndef OHOS_DAUDIO_LOG_H 17 #define OHOS_DAUDIO_LOG_H 18 19 #include <cstring> 20 #include <cinttypes> 21 22 #include "hilog/log.h" 23 24 namespace OHOS { 25 namespace DistributedHardware { 26 #undef LOG_TAG 27 #define LOG_TAG "DAUDIO" 28 29 typedef enum { 30 DH_LOG_DEBUG, 31 DH_LOG_INFO, 32 DH_LOG_WARN, 33 DH_LOG_ERROR, 34 } DHLogLevel; 35 36 void DHLog(DHLogLevel logLevel, const char *fmt, ...); 37 38 #define DHLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, \ 39 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 40 41 #define DHLOGI(fmt, ...) HILOG_INFO(LOG_CORE, \ 42 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 43 44 #define DHLOGW(fmt, ...) HILOG_WARN(LOG_CORE, \ 45 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 46 47 #define DHLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, \ 48 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 49 50 #define CHECK_NULL_RETURN(ptr, ret) \ 51 do { \ 52 if ((ptr) == nullptr) { \ 53 DHLOGE("Address pointer is null"); \ 54 return (ret); \ 55 } \ 56 } while (0) 57 58 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 59 do { \ 60 if ((cond)) { \ 61 DHLOGE(fmt, ##__VA_ARGS__); \ 62 return (ret); \ 63 } \ 64 } while (0) 65 66 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 67 do { \ 68 if ((cond)) { \ 69 DHLOGE(fmt, ##__VA_ARGS__); \ 70 return; \ 71 } \ 72 } while (0) 73 } // Distributedaudio 74 } // OHOS 75 #endif 76