1 /* 2 * Copyright 2022 Shenzhen Kaihong DID 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 CODEC_LOG_WRAPPER_H 17 #define CODEC_LOG_WRAPPER_H 18 #include <hdf_log.h> 19 namespace OHOS { 20 #define HDF_LOG_TAG codec_hdi_omx 21 22 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 23 #ifndef CODEC_DEBUG 24 #define CODEC_LOGE(fmt, ...) HDF_LOGE("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 25 #define CODEC_LOGW(fmt, ...) HDF_LOGW("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 26 #define CODEC_LOGI(fmt, ...) HDF_LOGI("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 27 #define CODEC_LOGD(fmt, ...) HDF_LOGD("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 28 #else 29 constexpr int32_t MAX_BUFFER_LEN = 256; 30 static FILE *fp = fopen("/data/codec.log", "rw"); 31 static void LOG(const char *fmt, ...) 32 { 33 va_list va; 34 va_start(va, fmt); 35 std::string stdFromat = fmt; 36 do { 37 std::size_t pos = stdFormat.find("{public}"); 38 if (pos == std::string::npos) { 39 break; 40 } 41 stdFormat = stdFormat.erase(pos, strlen("{public}")); 42 } while (true); 43 char buf[MAX_BUFFER_LEN] = {0}; 44 if (vsnprintf_s(buf, sizeof(buf), sizeof(buf), stdFormat.c_str(), va) <= 0) { 45 va_end(va); 46 return; 47 } 48 va_end(va); 49 if (fp != nullptr) { 50 fwrite(buf, strlen(buf), 1, fp); 51 fflush(fp); 52 } 53 } 54 #define CODEC_LOGE(fmt, ...) LOG("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 55 #define CODEC_LOGW(fmt, ...) LOG("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 56 #define CODEC_LOGI(fmt, ...) LOG("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 57 #define CODEC_LOGD(fmt, ...) LOG("[%{public}s] %{public}s# " fmt, FILENAME, __func__, ##__VA_ARGS__) 58 #endif 59 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 60 do { \ 61 if (!(cond)) { \ 62 CODEC_LOGE(fmt, ##__VA_ARGS__); \ 63 return ret; \ 64 } \ 65 } while (0) 66 } // namespace OHOS 67 #endif /* CODEC_LOG_WRAPPER_H */