1e0e9324cSopenharmony_ci/*
2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License.
5e0e9324cSopenharmony_ci * You may obtain a copy of the License at
6e0e9324cSopenharmony_ci *
7e0e9324cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0e9324cSopenharmony_ci *
9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and
13e0e9324cSopenharmony_ci * limitations under the License.
14e0e9324cSopenharmony_ci */
15e0e9324cSopenharmony_ci
16e0e9324cSopenharmony_ci#ifndef OHOS_SHARING_LOG_H
17e0e9324cSopenharmony_ci#define OHOS_SHARING_LOG_H
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_ci#include <cinttypes>
20e0e9324cSopenharmony_ci#include "hilog/log.h"
21e0e9324cSopenharmony_ci
22e0e9324cSopenharmony_cinamespace OHOS {
23e0e9324cSopenharmony_cinamespace Sharing {
24e0e9324cSopenharmony_ci#ifndef SHARING_LOG_TAG
25e0e9324cSopenharmony_ci#define SHARING_LOG_TAG "sharing"
26e0e9324cSopenharmony_ci#endif
27e0e9324cSopenharmony_ci
28e0e9324cSopenharmony_ci#ifndef SHARING_LOG_DOMAIN
29e0e9324cSopenharmony_ci#define SHARING_LOG_DOMAIN 0xD002B09
30e0e9324cSopenharmony_ci#define SHARING_SERVICE_TEMP_SA_ID  5527
31e0e9324cSopenharmony_ci#define SHARING_SERVICE_DOMAIN_TEMP_SA_ID   5528
32e0e9324cSopenharmony_ci#endif
33e0e9324cSopenharmony_ci
34e0e9324cSopenharmony_cistatic constexpr OHOS::HiviewDFX::HiLogLabel SHARING_LABEL = {LOG_CORE, SHARING_LOG_DOMAIN, SHARING_LOG_TAG};
35e0e9324cSopenharmony_ci
36e0e9324cSopenharmony_ci#define R_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
37e0e9324cSopenharmony_ci
38e0e9324cSopenharmony_ci#define SHARING_LOG(func, fmt, args...)                                                                            \
39e0e9324cSopenharmony_ci    do {                                                                                                             \
40e0e9324cSopenharmony_ci        (void)func(SHARING_LABEL, "[Sharing][%{public}s()][%{public}s:%{public}d] " fmt, __FUNCTION__, R_FILENAME,   \
41e0e9324cSopenharmony_ci                   __LINE__, ##args);                                                                                \
42e0e9324cSopenharmony_ci    } while (0)
43e0e9324cSopenharmony_ci
44e0e9324cSopenharmony_ci#define SHARING_LOGD(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__)
45e0e9324cSopenharmony_ci#define SHARING_LOGI(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
46e0e9324cSopenharmony_ci#define SHARING_LOGW(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__)
47e0e9324cSopenharmony_ci#define SHARING_LOGE(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__)
48e0e9324cSopenharmony_ci#define SHARING_LOGF(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Fatal, fmt, ##__VA_ARGS__)
49e0e9324cSopenharmony_ci
50e0e9324cSopenharmony_ci#define CHECK_AND_RETURN(cond)                                \
51e0e9324cSopenharmony_ci    do {                                                      \
52e0e9324cSopenharmony_ci        if (!(cond)) {                                        \
53e0e9324cSopenharmony_ci            SHARING_LOGE("%{public}s, check failed!", #cond); \
54e0e9324cSopenharmony_ci            return;                                           \
55e0e9324cSopenharmony_ci        }                                                     \
56e0e9324cSopenharmony_ci    } while (0)
57e0e9324cSopenharmony_ci
58e0e9324cSopenharmony_ci#define CHECK_AND_RETURN_RET(cond, ret)                                              \
59e0e9324cSopenharmony_ci    do {                                                                             \
60e0e9324cSopenharmony_ci        if (!(cond)) {                                                               \
61e0e9324cSopenharmony_ci            SHARING_LOGE("%{public}s, check failed! ret: %{public}s.", #cond, #ret);  \
62e0e9324cSopenharmony_ci            return ret;                                                              \
63e0e9324cSopenharmony_ci        }                                                                            \
64e0e9324cSopenharmony_ci    } while (0)
65e0e9324cSopenharmony_ci
66e0e9324cSopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \
67e0e9324cSopenharmony_ci    do {                                              \
68e0e9324cSopenharmony_ci        if (!(cond)) {                                \
69e0e9324cSopenharmony_ci            SHARING_LOGE(fmt, ##__VA_ARGS__);         \
70e0e9324cSopenharmony_ci            return ret;                               \
71e0e9324cSopenharmony_ci        }                                             \
72e0e9324cSopenharmony_ci    } while (0)
73e0e9324cSopenharmony_ci
74e0e9324cSopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...)  \
75e0e9324cSopenharmony_ci    do {                                      \
76e0e9324cSopenharmony_ci        if (!(cond)) {                        \
77e0e9324cSopenharmony_ci            SHARING_LOGE(fmt, ##__VA_ARGS__); \
78e0e9324cSopenharmony_ci            return;                           \
79e0e9324cSopenharmony_ci        }                                     \
80e0e9324cSopenharmony_ci    } while (0)
81e0e9324cSopenharmony_ci
82e0e9324cSopenharmony_ci} // namespace Sharing
83e0e9324cSopenharmony_ci} // namespace OHOS
84e0e9324cSopenharmony_ci#endif