xref: /base/useriam/pin_auth/common/logs/iam_logger.h (revision a339c2d4)
1a339c2d4Sopenharmony_ci/*
2a339c2d4Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3a339c2d4Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a339c2d4Sopenharmony_ci * you may not use this file except in compliance with the License.
5a339c2d4Sopenharmony_ci * You may obtain a copy of the License at
6a339c2d4Sopenharmony_ci *
7a339c2d4Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8a339c2d4Sopenharmony_ci *
9a339c2d4Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a339c2d4Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a339c2d4Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a339c2d4Sopenharmony_ci * See the License for the specific language governing permissions and
13a339c2d4Sopenharmony_ci * limitations under the License.
14a339c2d4Sopenharmony_ci */
15a339c2d4Sopenharmony_ci#ifndef IAM_LOGGER_H
16a339c2d4Sopenharmony_ci#define IAM_LOGGER_H
17a339c2d4Sopenharmony_ci
18a339c2d4Sopenharmony_ci#include "hilog/log.h"
19a339c2d4Sopenharmony_cinamespace OHOS {
20a339c2d4Sopenharmony_cinamespace UserIam {
21a339c2d4Sopenharmony_cinamespace Common {
22a339c2d4Sopenharmony_ci#ifdef __FILE_NAME__
23a339c2d4Sopenharmony_ci#define PIN_AUTH_FILE __FILE_NAME__
24a339c2d4Sopenharmony_ci#else
25a339c2d4Sopenharmony_ci#define PIN_AUTH_FILE (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
26a339c2d4Sopenharmony_ci#endif
27a339c2d4Sopenharmony_ci
28a339c2d4Sopenharmony_ci#ifdef LOG_DOMAIN
29a339c2d4Sopenharmony_ci#undef LOG_DOMAIN
30a339c2d4Sopenharmony_ci#endif
31a339c2d4Sopenharmony_ci
32a339c2d4Sopenharmony_ci#define LOG_DOMAIN 0xD002404
33a339c2d4Sopenharmony_ci
34a339c2d4Sopenharmony_ci#ifdef LOG_TAG
35a339c2d4Sopenharmony_ci#undef LOG_TAG
36a339c2d4Sopenharmony_ci#endif
37a339c2d4Sopenharmony_ci
38a339c2d4Sopenharmony_ci#define PIN_LOG_DEBUG(...) HILOG_DEBUG(LOG_CORE, __VA_ARGS__)
39a339c2d4Sopenharmony_ci#define PIN_LOG_INFO(...) HILOG_INFO(LOG_CORE, __VA_ARGS__)
40a339c2d4Sopenharmony_ci#define PIN_LOG_WARN(...) HILOG_WARN(LOG_CORE, __VA_ARGS__)
41a339c2d4Sopenharmony_ci#define PIN_LOG_ERROR(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__)
42a339c2d4Sopenharmony_ci#define PIN_LOG_FATAL(...) HILOG_FATAL(LOG_CORE, __VA_ARGS__)
43a339c2d4Sopenharmony_ci
44a339c2d4Sopenharmony_ci#define ARGS(fmt, ...) "[%{public}s@%{public}s:%{public}d] " fmt, __FUNCTION__, PIN_AUTH_FILE, __LINE__, ##__VA_ARGS__
45a339c2d4Sopenharmony_ci#define PIN_LOG(level, ...) PIN_LOG_##level(ARGS(__VA_ARGS__))
46a339c2d4Sopenharmony_ci
47a339c2d4Sopenharmony_ci#define IAM_LOGD(...) PIN_LOG(DEBUG, __VA_ARGS__)
48a339c2d4Sopenharmony_ci#define IAM_LOGI(...) PIN_LOG(INFO, __VA_ARGS__)
49a339c2d4Sopenharmony_ci#define IAM_LOGW(...) PIN_LOG(WARN, __VA_ARGS__)
50a339c2d4Sopenharmony_ci#define IAM_LOGE(...) PIN_LOG(ERROR, __VA_ARGS__)
51a339c2d4Sopenharmony_ci#define IAM_LOGF(...) PIN_LOG(FATAL, __VA_ARGS__)
52a339c2d4Sopenharmony_ci
53a339c2d4Sopenharmony_ci} // namespace Common
54a339c2d4Sopenharmony_ci} // namespace UserIam
55a339c2d4Sopenharmony_ci} // namespace OHOS
56a339c2d4Sopenharmony_ci
57a339c2d4Sopenharmony_ci#endif // IAM_LOGGER_H
58