1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 #ifndef OHOS_SP_LOG_H 16 #define OHOS_SP_LOG_H 17 #include <string> 18 namespace OHOS { 19 namespace SmartPerf { 20 typedef enum { 21 SP_LOG_DEBUG, 22 SP_LOG_INFO, 23 SP_LOG_WARN, 24 SP_LOG_ERROR, 25 } SpLogLevel; 26 27 void SpLog(SpLogLevel logLevel, bool isWriteLog, const char *fmt, ...); 28 29 #define LOGD(fmt, ...) \ 30 SpLog(SP_LOG_DEBUG, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 31 ##__VA_ARGS__) 32 33 #define LOGI(fmt, ...) \ 34 SpLog(SP_LOG_INFO, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 35 ##__VA_ARGS__) 36 37 #define LOGW(fmt, ...) \ 38 SpLog(SP_LOG_WARN, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 39 ##__VA_ARGS__) 40 41 #define LOGE(fmt, ...) \ 42 SpLog(SP_LOG_ERROR, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 43 ##__VA_ARGS__) 44 45 #define WLOGD(fmt, ...) \ 46 SpLog(SP_LOG_DEBUG, true, (std::string("[Debug][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 47 ##__VA_ARGS__) 48 49 #define WLOGI(fmt, ...) \ 50 SpLog(SP_LOG_INFO, true, (std::string("[Info][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 51 ##__VA_ARGS__) 52 53 #define WLOGW(fmt, ...) \ 54 SpLog(SP_LOG_WARN, true, (std::string("[Warning][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 55 ##__VA_ARGS__) 56 57 #define WLOGE(fmt, ...) \ 58 SpLog(SP_LOG_ERROR, true, (std::string("[Error][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \ 59 ##__VA_ARGS__) 60 61 void EnableWriteLogAndDeleteOldLogFiles(); 62 void EscapeForCSV(std::string str); 63 } // namespace SmartPerf 64 } // namespace OHOS 65 #endif // OHOS_SP_LOG_H