1 /* 2 * Copyright (c) 2023 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 __LOG_BASE_H__ 17 #define __LOG_BASE_H__ 18 19 #include <stdio.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define FFRT_LOG_ERROR (0) 26 #define FFRT_LOG_WARN (1) 27 #define FFRT_LOG_INFO (2) 28 #define FFRT_LOG_DEBUG (3) 29 #define FFRT_LOG_LEVEL_MAX (FFRT_LOG_DEBUG + 1) 30 31 void LogErr(const char* format, ...); 32 void LogWarn(const char* format, ...); 33 void LogInfo(const char* format, ...); 34 void LogDebug(const char* format, ...); 35 36 int GetLogLevel(void); 37 unsigned int GetLogId(void); 38 39 #define FFRT_LOG(level, format, ...) \ 40 do { \ 41 if ((level) > GetLogLevel()) \ 42 break; \ 43 if (level == FFRT_LOG_ERROR) { \ 44 LogErr("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 45 } else if (level == FFRT_LOG_WARN) { \ 46 LogWarn("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 47 } else if (level == FFRT_LOG_INFO) { \ 48 LogInfo("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 49 } else if (level == FFRT_LOG_DEBUG) { \ 50 LogDebug("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 51 } else { \ 52 printf("Log Level is Invalid!"); \ 53 } \ 54 } while (0) 55 56 // short log for more infomation 57 #define FFRT_BBOX_LOG(format, ...) LogErr(format "\n", ##__VA_ARGS__) 58 59 #ifdef __cplusplus 60 } 61 #endif 62 #endif // __LOG_BASE_H__