1 /*
2 * Copyright (C) 2024 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 // ############################# enum define ###################################
16 #ifndef HDC_LOG_H
17 #define HDC_LOG_H
18
19 #include <cinttypes>
20 #include <cstdarg>
21 #include <string>
22 #include "base.h"
23
24 namespace Hdc {
25 using namespace std;
26
27 enum LogLevel {
28 LOG_OFF,
29 LOG_FATAL,
30 LOG_WARN,
31 LOG_INFO, // default
32 LOG_DEBUG,
33 LOG_ALL,
34 LOG_VERBOSE,
35 LOG_LAST = LOG_VERBOSE, // tail, not use
36 };
37
GetFileNameAny(const string & path)38 inline string GetFileNameAny(const string &path)
39 {
40 string tmpString = path;
41 size_t tmpNum = tmpString.rfind('/');
42 if (tmpNum == std::string::npos) {
43 tmpNum = tmpString.rfind('\\');
44 if (tmpNum == std::string::npos) {
45 return tmpString;
46 }
47 }
48 tmpString = tmpString.substr(tmpNum + 1, tmpString.size() - tmpNum);
49 return tmpString;
50 }
51
52 void PrintLogEx(const char *functionName, int line, uint8_t logLevel, const char *msg, ...);
53
54 #define WRITE_LOG(level, fmt, ...) PrintLogEx(__FILE__, __LINE__, level, fmt, ##__VA_ARGS__)
55 }
56 #endif
57