13e5483f6Sopenharmony_ci/*
23e5483f6Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
33e5483f6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43e5483f6Sopenharmony_ci * you may not use this file except in compliance with the License.
53e5483f6Sopenharmony_ci * You may obtain a copy of the License at
63e5483f6Sopenharmony_ci *
73e5483f6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83e5483f6Sopenharmony_ci *
93e5483f6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103e5483f6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113e5483f6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123e5483f6Sopenharmony_ci * See the License for the specific language governing permissions and
133e5483f6Sopenharmony_ci * limitations under the License.
143e5483f6Sopenharmony_ci */
153e5483f6Sopenharmony_ci
163e5483f6Sopenharmony_ci#ifndef OHOS_RINGTONE_LOG_H
173e5483f6Sopenharmony_ci#define OHOS_RINGTONE_LOG_H
183e5483f6Sopenharmony_ci
193e5483f6Sopenharmony_ci#ifndef MLOG_TAG
203e5483f6Sopenharmony_ci#define MLOG_TAG "Common"
213e5483f6Sopenharmony_ci#endif
223e5483f6Sopenharmony_ci
233e5483f6Sopenharmony_ci#undef LOG_DOMAIN
243e5483f6Sopenharmony_ci#define LOG_DOMAIN 0xD002B76
253e5483f6Sopenharmony_ci
263e5483f6Sopenharmony_ci#undef LOG_TAG
273e5483f6Sopenharmony_ci#define LOG_TAG "RingtoneLibrary"
283e5483f6Sopenharmony_ci
293e5483f6Sopenharmony_ci#ifndef LOG_LABEL
303e5483f6Sopenharmony_ci#define LOG_LABEL { LOG_CORE, LOG_DOMAIN, LOG_TAG }
313e5483f6Sopenharmony_ci#endif
323e5483f6Sopenharmony_ci
333e5483f6Sopenharmony_ci#include "hilog/log.h"
343e5483f6Sopenharmony_ci
353e5483f6Sopenharmony_ci#define RINGTONE_HILOG(op, type, fmt, args...) \
363e5483f6Sopenharmony_ci    do {                                  \
373e5483f6Sopenharmony_ci        op(LOG_CORE, type, LOG_DOMAIN, LOG_TAG, MLOG_TAG ":{%{public}s:%{public}d} " fmt, __FUNCTION__, __LINE__, \
383e5483f6Sopenharmony_ci            ##args);  \
393e5483f6Sopenharmony_ci    } while (0)
403e5483f6Sopenharmony_ci
413e5483f6Sopenharmony_ci#define RINGTONE_DEBUG_LOG(fmt, ...) RINGTONE_HILOG(HILOG_IMPL, LOG_DEBUG, fmt, ##__VA_ARGS__)
423e5483f6Sopenharmony_ci#define RINGTONE_ERR_LOG(fmt, ...) RINGTONE_HILOG(HILOG_IMPL, LOG_ERROR, fmt, ##__VA_ARGS__)
433e5483f6Sopenharmony_ci#define RINGTONE_WARN_LOG(fmt, ...) RINGTONE_HILOG(HILOG_IMPL, LOG_WARN, fmt, ##__VA_ARGS__)
443e5483f6Sopenharmony_ci#define RINGTONE_INFO_LOG(fmt, ...) RINGTONE_HILOG(HILOG_IMPL, LOG_INFO, fmt, ##__VA_ARGS__)
453e5483f6Sopenharmony_ci#define RINGTONE_FATAL_LOG(fmt, ...) RINGTONE_HILOG(HILOG_IMPL, LOG_FATAL, fmt, ##__VA_ARGS__)
463e5483f6Sopenharmony_ci
473e5483f6Sopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
483e5483f6Sopenharmony_ci    do {                                               \
493e5483f6Sopenharmony_ci        if (!(cond)) {                                 \
503e5483f6Sopenharmony_ci            RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
513e5483f6Sopenharmony_ci            return ret;                                \
523e5483f6Sopenharmony_ci        }                                              \
533e5483f6Sopenharmony_ci    } while (0)
543e5483f6Sopenharmony_ci
553e5483f6Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
563e5483f6Sopenharmony_ci    do {                                               \
573e5483f6Sopenharmony_ci        if (!(cond)) {                                 \
583e5483f6Sopenharmony_ci            RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
593e5483f6Sopenharmony_ci            return;                                    \
603e5483f6Sopenharmony_ci        }                                              \
613e5483f6Sopenharmony_ci    } while (0)
623e5483f6Sopenharmony_ci
633e5483f6Sopenharmony_ci#define CHECK_AND_PRINT_LOG(cond, fmt, ...)            \
643e5483f6Sopenharmony_ci    do {                                               \
653e5483f6Sopenharmony_ci        if (!(cond)) {                                 \
663e5483f6Sopenharmony_ci            RINGTONE_ERR_LOG(fmt, ##__VA_ARGS__);         \
673e5483f6Sopenharmony_ci        }                                              \
683e5483f6Sopenharmony_ci    } while (0)
693e5483f6Sopenharmony_ci
703e5483f6Sopenharmony_ci#define CHECK_AND_RETURN_RET(cond, ret)  \
713e5483f6Sopenharmony_ci    do {                                               \
723e5483f6Sopenharmony_ci        if (!(cond)) {                                 \
733e5483f6Sopenharmony_ci            return ret;                                \
743e5483f6Sopenharmony_ci        }                                              \
753e5483f6Sopenharmony_ci    } while (0)
763e5483f6Sopenharmony_ci
773e5483f6Sopenharmony_ci#endif // OHOS_RINGTONE_LOG_H
78