1/*
2 * Copyright (c) 2022 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 LD_LOG_H
17#define LD_LOG_H
18
19#include <musl_log.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define LD_LOG_ERROR 1
26#define LD_LOG_WARNING 2
27#define LD_LOG_INFO 4
28#define LD_LOG_DEBUG 8
29
30#define LD_LOG_LEVEL (LD_LOG_ERROR | LD_LOG_WARNING | LD_LOG_INFO)
31
32#define LD_LOG_TAG "MUSL-LDSO"
33
34hidden bool get_ld_log_enable();
35hidden void ld_log_reset();
36
37hidden bool is_dlclose_debug_enable();
38
39#if ((LD_LOG_LEVEL & LD_LOG_ERROR) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG)))
40#define LD_LOGE(...) (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__);
41#else
42#define LD_LOGE(...)
43#endif
44
45#if ((LD_LOG_LEVEL & LD_LOG_WARNING) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG)))
46#define LD_LOGW(...) if (get_ld_log_enable()) {   \
47    (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_WARN, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__); \
48}
49#else
50#define LD_LOGW(...)
51#endif
52
53#if ((LD_LOG_LEVEL & LD_LOG_INFO) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG)))
54#define LD_LOGI(...) if (get_ld_log_enable()) {   \
55    (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_INFO, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__);    \
56}
57#else
58#define LD_LOGI(...)
59#endif
60
61#if (LD_LOG_LEVEL & LD_LOG_DEBUG) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG))
62#define LD_LOGD(...) if (get_ld_log_enable()) {   \
63    (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_DEBUG, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__);    \
64}
65#else
66#define LD_LOGD(...)
67#endif
68
69#ifdef __cplusplus
70}
71#endif
72
73#endif  // LD_LOG_H
74