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 GetFFRTLogLevel(void); 37 void SetFFRTLogLevel(int level); 38 unsigned int GetLogId(void); 39 40 #define FFRT_LOG(level, format, ...) \ 41 do { \ 42 if ((level) > GetFFRTLogLevel()) \ 43 break; \ 44 if (level == FFRT_LOG_ERROR) { \ 45 LogErr("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 46 } else if (level == FFRT_LOG_WARN) { \ 47 LogWarn("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 48 } else if (level == FFRT_LOG_INFO) { \ 49 LogInfo("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 50 } else if (level == FFRT_LOG_DEBUG) { \ 51 LogDebug("%u:%s:%d " format "\n", GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \ 52 } else { \ 53 printf("Log Level is Invalid!"); \ 54 } \ 55 } while (0) 56 57 // short log for more infomation 58 #define FFRT_BBOX_LOG(format, ...) LogErr(format "\n", ##__VA_ARGS__) 59 60 #ifdef __cplusplus 61 } 62 #endif 63 #endif // __LOG_BASE_H__