• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const std::string LOG_FILE_DIR = "/data/local/tmp/spdaemonlog/";
21 typedef enum {
22     SP_LOG_DEBUG,
23     SP_LOG_INFO,
24     SP_LOG_WARN,
25     SP_LOG_ERROR,
26 } SpLogLevel;
27 
28 void SpLog(SpLogLevel logLevel, bool isWriteLog, const char *fmt, ...);
29 
30 #define LOGD(fmt, ...) \
31     SpLog(SP_LOG_DEBUG, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
32         ##__VA_ARGS__)
33 
34 #define LOGI(fmt, ...) \
35     SpLog(SP_LOG_INFO, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
36         ##__VA_ARGS__)
37 
38 #define LOGW(fmt, ...) \
39     SpLog(SP_LOG_WARN, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
40         ##__VA_ARGS__)
41 
42 #define LOGE(fmt, ...) \
43     SpLog(SP_LOG_ERROR, false, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
44         ##__VA_ARGS__)
45 
46 #define WLOGD(fmt, ...) \
47     SpLog(SP_LOG_DEBUG, true, (std::string("[Debug][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
48         ##__VA_ARGS__)
49 
50 #define WLOGI(fmt, ...) \
51     SpLog(SP_LOG_INFO, true, (std::string("[Info][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
52         ##__VA_ARGS__)
53 
54 #define WLOGW(fmt, ...) \
55     SpLog(SP_LOG_WARN, true, (std::string("[Warning][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
56         ##__VA_ARGS__)
57 
58 #define WLOGE(fmt, ...) \
59     SpLog(SP_LOG_ERROR, true, (std::string("[Error][") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), \
60         ##__VA_ARGS__)
61 
62 void EnableWriteLogAndDeleteOldLogFiles();
63 void EscapeForCSV(std::string str);
64 } // namespace SmartPerf
65 } // namespace OHOS
66 #endif // OHOS_SP_LOG_H