119e95205Sopenharmony_ci/* 219e95205Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 419e95205Sopenharmony_ci * you may not use this file except in compliance with the License. 519e95205Sopenharmony_ci * You may obtain a copy of the License at 619e95205Sopenharmony_ci * 719e95205Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 819e95205Sopenharmony_ci * 919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and 1319e95205Sopenharmony_ci * limitations under the License. 1419e95205Sopenharmony_ci */ 1519e95205Sopenharmony_ci 1619e95205Sopenharmony_ci#ifndef LOG_H 1719e95205Sopenharmony_ci#define LOG_H 1819e95205Sopenharmony_ci 1919e95205Sopenharmony_ci#undef LOG_DOMAIN 2019e95205Sopenharmony_ci#define LOG_DOMAIN 0xD000102 2119e95205Sopenharmony_ci#ifndef LOG_TAG 2219e95205Sopenharmony_ci#define LOG_TAG "Bluetooth" 2319e95205Sopenharmony_ci#endif 2419e95205Sopenharmony_ci 2519e95205Sopenharmony_ci#include "hilog/log.h" 2619e95205Sopenharmony_ci 2719e95205Sopenharmony_ci#ifdef HILOGF 2819e95205Sopenharmony_ci#undef HILOGF 2919e95205Sopenharmony_ci#endif 3019e95205Sopenharmony_ci 3119e95205Sopenharmony_ci#ifdef HILOGE 3219e95205Sopenharmony_ci#undef HILOGE 3319e95205Sopenharmony_ci#endif 3419e95205Sopenharmony_ci 3519e95205Sopenharmony_ci#ifdef HILOGW 3619e95205Sopenharmony_ci#undef HILOGW 3719e95205Sopenharmony_ci#endif 3819e95205Sopenharmony_ci 3919e95205Sopenharmony_ci#ifdef HILOGI 4019e95205Sopenharmony_ci#undef HILOGI 4119e95205Sopenharmony_ci#endif 4219e95205Sopenharmony_ci 4319e95205Sopenharmony_ci#ifdef HILOGD 4419e95205Sopenharmony_ci#undef HILOGD 4519e95205Sopenharmony_ci#endif 4619e95205Sopenharmony_ci 4719e95205Sopenharmony_ci#define FILENAME_SHORT (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 4819e95205Sopenharmony_ci 4919e95205Sopenharmony_ci#define HILOGD(fmt, ...) \ 5019e95205Sopenharmony_ci HILOG_DEBUG(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, \ 5119e95205Sopenharmony_ci FILENAME_SHORT, __FUNCTION__, __LINE__, ##__VA_ARGS__) 5219e95205Sopenharmony_ci#define HILOGI(fmt, ...) \ 5319e95205Sopenharmony_ci HILOG_INFO(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, \ 5419e95205Sopenharmony_ci FILENAME_SHORT, __FUNCTION__, __LINE__, ##__VA_ARGS__) 5519e95205Sopenharmony_ci#define HILOGW(fmt, ...) \ 5619e95205Sopenharmony_ci HILOG_WARN(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, \ 5719e95205Sopenharmony_ci FILENAME_SHORT, __FUNCTION__, __LINE__, ##__VA_ARGS__) 5819e95205Sopenharmony_ci#define HILOGE(fmt, ...) \ 5919e95205Sopenharmony_ci HILOG_ERROR(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, \ 6019e95205Sopenharmony_ci FILENAME_SHORT, __FUNCTION__, __LINE__, ##__VA_ARGS__) 6119e95205Sopenharmony_ci#define HILOGF(fmt, ...) \ 6219e95205Sopenharmony_ci HILOG_FATAL(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, \ 6319e95205Sopenharmony_ci FILENAME_SHORT, __FUNCTION__, __LINE__, ##__VA_ARGS__) 6419e95205Sopenharmony_ci 6519e95205Sopenharmony_ci#ifdef LOG_DEBUG 6619e95205Sopenharmony_ci#undef LOG_DEBUG 6719e95205Sopenharmony_ci#endif 6819e95205Sopenharmony_ci 6919e95205Sopenharmony_ci#ifdef LOG_INFO 7019e95205Sopenharmony_ci#undef LOG_INFO 7119e95205Sopenharmony_ci#endif 7219e95205Sopenharmony_ci 7319e95205Sopenharmony_ci#ifdef LOG_WARN 7419e95205Sopenharmony_ci#undef LOG_WARN 7519e95205Sopenharmony_ci#endif 7619e95205Sopenharmony_ci 7719e95205Sopenharmony_ci#ifdef LOG_ERROR 7819e95205Sopenharmony_ci#undef LOG_ERROR 7919e95205Sopenharmony_ci#endif 8019e95205Sopenharmony_ci 8119e95205Sopenharmony_ci#ifdef LOG_FATAL 8219e95205Sopenharmony_ci#undef LOG_FATAL 8319e95205Sopenharmony_ci#endif 8419e95205Sopenharmony_ci 8519e95205Sopenharmony_ci#ifdef DEBUG 8619e95205Sopenharmony_ci#include <assert.h> 8719e95205Sopenharmony_ci#define ASSERT(x) assert(x) 8819e95205Sopenharmony_ci#else 8919e95205Sopenharmony_ci#define ASSERT(x) 9019e95205Sopenharmony_ci#endif 9119e95205Sopenharmony_ci 9219e95205Sopenharmony_ci#ifdef DEBUG 9319e95205Sopenharmony_ci#include <assert.h> 9419e95205Sopenharmony_ci#define ASSERT_LOG(x, fmt, args...) \ 9519e95205Sopenharmony_ci do { \ 9619e95205Sopenharmony_ci if (!(x)) { \ 9719e95205Sopenharmony_ci HILOGE("assertion '" #x"' failed - " fmt, ##args); \ 9819e95205Sopenharmony_ci } \ 9919e95205Sopenharmony_ci } while (false) 10019e95205Sopenharmony_ci#else 10119e95205Sopenharmony_ci#define ASSERT_LOG(x, fmt, args...) 10219e95205Sopenharmony_ci#endif 10319e95205Sopenharmony_ci 10419e95205Sopenharmony_ci#define LOG_VERBOSE(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__) 10519e95205Sopenharmony_ci#define LOG_DEBUG(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__) 10619e95205Sopenharmony_ci#define LOG_INFO(...) HILOG_INFO(LOG_CORE, __VA_ARGS__) 10719e95205Sopenharmony_ci#define LOG_WARN(...) HILOG_WARN(LOG_CORE, __VA_ARGS__) 10819e95205Sopenharmony_ci#define LOG_ERROR(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__) 10919e95205Sopenharmony_ci#define LOG_FATAL(...) HILOG_FATAL(LOG_CORE, __VA_ARGS__) 11019e95205Sopenharmony_ci 11119e95205Sopenharmony_ci#define ALOGV(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__) 11219e95205Sopenharmony_ci#define ALOGD(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__) 11319e95205Sopenharmony_ci#define ALOGI(...) HILOG_WARN(LOG_CORE, __VA_ARGS__) 11419e95205Sopenharmony_ci#define ALOGW(...) HILOG_WARN(LOG_CORE, __VA_ARGS__) 11519e95205Sopenharmony_ci#define ALOGE(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__) 11619e95205Sopenharmony_ci 11719e95205Sopenharmony_ci#ifndef LOG_EVENT_INT 11819e95205Sopenharmony_ci#define LOG_EVENT_INT(tag, subTag) LOG_ERROR("ERROR tag num: 0x%x, opcode: %ld", tag, subTag) 11919e95205Sopenharmony_ci#endif 12019e95205Sopenharmony_ci 12119e95205Sopenharmony_ci#ifdef CHECK_AND_RETURN_LOG 12219e95205Sopenharmony_ci#undef CHECK_AND_RETURN_LOG 12319e95205Sopenharmony_ci#endif 12419e95205Sopenharmony_ci 12519e95205Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 12619e95205Sopenharmony_ci do { \ 12719e95205Sopenharmony_ci if (!(cond)) { \ 12819e95205Sopenharmony_ci HILOGE(fmt, ##__VA_ARGS__); \ 12919e95205Sopenharmony_ci return; \ 13019e95205Sopenharmony_ci } \ 13119e95205Sopenharmony_ci } while (0) 13219e95205Sopenharmony_ci 13319e95205Sopenharmony_ci#ifdef CHECK_AND_RETURN_LOG_RET 13419e95205Sopenharmony_ci#undef CHECK_AND_RETURN_LOG_RET 13519e95205Sopenharmony_ci#endif 13619e95205Sopenharmony_ci 13719e95205Sopenharmony_ci#define CHECK_AND_RETURN_LOG_RET(cond, ret, fmt, ...) \ 13819e95205Sopenharmony_ci do { \ 13919e95205Sopenharmony_ci if (!(cond)) { \ 14019e95205Sopenharmony_ci HILOGE(fmt, ##__VA_ARGS__); \ 14119e95205Sopenharmony_ci return ret; \ 14219e95205Sopenharmony_ci } \ 14319e95205Sopenharmony_ci } while (0) 14419e95205Sopenharmony_ci 14519e95205Sopenharmony_ci#endif // LOG_H 146