1 /*
2  * Copyright (c) 2021 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 NETNATIVE_LOG_WRAPPER_H
17 #define NETNATIVE_LOG_WRAPPER_H
18 
19 #include <string>
20 #include <memory>
21 #include "hilog/log.h"
22 
23 #undef LOG_TAG
24 #ifndef NETMGRNATIVE_LOG_TAG
25 #define LOG_TAG "NetsysNativeService"
26 #else
27 #define LOG_TAG NETMGRNATIVE_LOG_TAG
28 #endif
29 
30 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
31 
32 #define PRINT_NATIVE_LOG(op, fmt, ...)                                                                               \
33     (void)HILOG_##op(LOG_CORE, "[%{public}s:%{public}d]" fmt,  \
34                                     FILENAME, __LINE__, ##__VA_ARGS__)
35 
36 #define NETNATIVE_LOG_D(fmt, ...) PRINT_NATIVE_LOG(DEBUG, fmt, ##__VA_ARGS__)
37 #define NETNATIVE_LOGE(fmt, ...) PRINT_NATIVE_LOG(ERROR, fmt, ##__VA_ARGS__)
38 #define NETNATIVE_LOGW(fmt, ...) PRINT_NATIVE_LOG(WARN, fmt, ##__VA_ARGS__)
39 #define NETNATIVE_LOGI(fmt, ...) PRINT_NATIVE_LOG(INFO, fmt, ##__VA_ARGS__)
40 #define NETNATIVE_LOGF(fmt, ...) PRINT_NATIVE_LOG(FATAL, fmt, ##__VA_ARGS__)
41 
42 #endif // NETNATIVE_LOG_WRAPPER_H