114cf0368Sopenharmony_ci/*
214cf0368Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
314cf0368Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
414cf0368Sopenharmony_ci * you may not use this file except in compliance with the License.
514cf0368Sopenharmony_ci * You may obtain a copy of the License at
614cf0368Sopenharmony_ci *
714cf0368Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
814cf0368Sopenharmony_ci *
914cf0368Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1014cf0368Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1114cf0368Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1214cf0368Sopenharmony_ci * See the License for the specific language governing permissions and
1314cf0368Sopenharmony_ci * limitations under the License.
1414cf0368Sopenharmony_ci */
1514cf0368Sopenharmony_ci
1614cf0368Sopenharmony_ci#ifndef UDMF_LOGGER_H
1714cf0368Sopenharmony_ci#define UDMF_LOGGER_H
1814cf0368Sopenharmony_ci#include <memory>
1914cf0368Sopenharmony_ci
2014cf0368Sopenharmony_ci#include "hilog/log.h"
2114cf0368Sopenharmony_ci
2214cf0368Sopenharmony_cinamespace OHOS {
2314cf0368Sopenharmony_cinamespace UDMF {
2414cf0368Sopenharmony_ci// param of log interface, such as UDMF_LABEL.
2514cf0368Sopenharmony_cienum UdmfSubModule {
2614cf0368Sopenharmony_ci    UDMF_FRAMEWORK = 0, // for framework core module
2714cf0368Sopenharmony_ci    UDMF_KITS_INNER,    // for udmf innerkits module
2814cf0368Sopenharmony_ci    UDMF_KITS_NAPI,     // for udmf napi kits module
2914cf0368Sopenharmony_ci    UDMF_CLIENT,        // for udmf client module
3014cf0368Sopenharmony_ci    UDMF_SERVICE,       // for udmf service module
3114cf0368Sopenharmony_ci    UDMF_CAPI,          // for udmf capi module
3214cf0368Sopenharmony_ci    UDMF_TEST,          // for udmf test module
3314cf0368Sopenharmony_ci};
3414cf0368Sopenharmony_ci
3514cf0368Sopenharmony_ci// 0xD001600: subsystem:distributeddatamgr module:udmf, 8 bits reserved.
3614cf0368Sopenharmony_cistatic inline OHOS::HiviewDFX::HiLogLabel LogLabel()
3714cf0368Sopenharmony_ci{
3814cf0368Sopenharmony_ci    return { LOG_CORE, 0xD001656, "UDMF" };
3914cf0368Sopenharmony_ci}
4014cf0368Sopenharmony_ci
4114cf0368Sopenharmony_ci// In order to improve performance, do not check the module range.
4214cf0368Sopenharmony_ci// Besides, make sure module is less than UDMF_SERVICE.
4314cf0368Sopenharmony_ci#define LOG_FATAL(module, fmt, ...)                                                 \
4414cf0368Sopenharmony_ci    do {                                                                            \
4514cf0368Sopenharmony_ci        auto lable = LogLabel();                                                    \
4614cf0368Sopenharmony_ci        if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) {       \
4714cf0368Sopenharmony_ci            break;                                                                  \
4814cf0368Sopenharmony_ci        }                                                                           \
4914cf0368Sopenharmony_ci        ((void)HILOG_IMPL(lable.type, LogLevel::LOG_FATAL, lable.domain, lable.tag, \
5014cf0368Sopenharmony_ci                          LOG_TAG ":%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
5114cf0368Sopenharmony_ci    } while (0)
5214cf0368Sopenharmony_ci
5314cf0368Sopenharmony_ci#define LOG_ERROR(module, fmt, ...)                                                 \
5414cf0368Sopenharmony_ci    do {                                                                            \
5514cf0368Sopenharmony_ci        auto lable = LogLabel();                                                    \
5614cf0368Sopenharmony_ci        if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) {       \
5714cf0368Sopenharmony_ci            break;                                                                  \
5814cf0368Sopenharmony_ci        }                                                                           \
5914cf0368Sopenharmony_ci        ((void)HILOG_IMPL(lable.type, LogLevel::LOG_ERROR, lable.domain, lable.tag, \
6014cf0368Sopenharmony_ci                          LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
6114cf0368Sopenharmony_ci    } while (0)
6214cf0368Sopenharmony_ci
6314cf0368Sopenharmony_ci#define LOG_WARN(module, fmt, ...)                                                  \
6414cf0368Sopenharmony_ci    do {                                                                            \
6514cf0368Sopenharmony_ci        auto lable = LogLabel();                                                    \
6614cf0368Sopenharmony_ci        if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) {        \
6714cf0368Sopenharmony_ci            break;                                                                  \
6814cf0368Sopenharmony_ci        }                                                                           \
6914cf0368Sopenharmony_ci        ((void)HILOG_IMPL(lable.type, LogLevel::LOG_WARN, lable.domain, lable.tag,  \
7014cf0368Sopenharmony_ci                          LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
7114cf0368Sopenharmony_ci    } while (0)
7214cf0368Sopenharmony_ci
7314cf0368Sopenharmony_ci#define LOG_INFO(module, fmt, ...)                                                  \
7414cf0368Sopenharmony_ci    do {                                                                            \
7514cf0368Sopenharmony_ci        auto lable = LogLabel();                                                    \
7614cf0368Sopenharmony_ci        if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) {        \
7714cf0368Sopenharmony_ci            break;                                                                  \
7814cf0368Sopenharmony_ci        }                                                                           \
7914cf0368Sopenharmony_ci        ((void)HILOG_IMPL(lable.type, LogLevel::LOG_INFO, lable.domain, lable.tag,  \
8014cf0368Sopenharmony_ci                          LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
8114cf0368Sopenharmony_ci    } while (0)
8214cf0368Sopenharmony_ci
8314cf0368Sopenharmony_ci#define LOG_DEBUG(module, fmt, ...)                                                 \
8414cf0368Sopenharmony_ci    do {                                                                            \
8514cf0368Sopenharmony_ci        auto lable = LogLabel();                                                    \
8614cf0368Sopenharmony_ci        if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) {       \
8714cf0368Sopenharmony_ci            break;                                                                  \
8814cf0368Sopenharmony_ci        }                                                                           \
8914cf0368Sopenharmony_ci        ((void)HILOG_IMPL(lable.type, LogLevel::LOG_DEBUG, lable.domain, lable.tag, \
9014cf0368Sopenharmony_ci                          LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
9114cf0368Sopenharmony_ci    } while (0)
9214cf0368Sopenharmony_ci} // namespace UDMF
9314cf0368Sopenharmony_ci} // namespace OHOS
9414cf0368Sopenharmony_ci#endif // UDMF_LOGGER_H
95