• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef ACCESSTOKEN_KLOG_H
16 #define ACCESSTOKEN_KLOG_H
17 
18 #include <inttypes.h>
19 #include "accesstoken_thread_msg.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 typedef enum NativeTokenKLogLevel {
28     NATIVETOKEN_KERROR = 0,
29     NATIVETOKEN_KWARN,
30     NATIVETOKEN_KINFO,
31 } NativeTokenKLogLevel;
32 
33 extern int NativeTokenKmsg(int logLevel, const char *fmt, ...);
34 
35 #define LOG_PUBLIC ""
36 
37 #define LOGE(fmt, ...)            \
38     ((void)NativeTokenKmsg(NATIVETOKEN_KERROR, "[%s:%d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
39 #define LOGW(fmt, ...)            \
40     ((void)NativeTokenKmsg(NATIVETOKEN_KWARN, "[%s:%d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
41 #define LOGI(fmt, ...)            \
42     ((void)NativeTokenKmsg(NATIVETOKEN_KINFO, "[%s:%d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__))
43 
44 // LOGC is used for critical errors that should be logged and reported.
45 #define LOGC(fmt, ...)            \
46 do { \
47     (void)NativeTokenKmsg(NATIVETOKEN_KERROR, "[%s:%d]" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
48     AddEventMessage(0, 0, \
49         "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
50 } while (0)
51 
52 #ifdef __cplusplus
53 #if __cplusplus
54 }
55 #endif /* __cplusplus */
56 #endif /* __cplusplus */
57 
58 #endif // ACCESSTOKEN_KLOG_H
59