• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHPP_LOG_H_
18 #define CHPP_LOG_H_
19 
20 // Defines CHRE macros that are necessary to compile CHPP (for compilers other
21 // than GCC / clang)
22 #ifndef IS_CHPP_BUILD
23 #define IS_CHPP_BUILD
24 #endif
25 
26 #include "chpp/platform/platform_log.h"
27 #include "chre/util/log_common.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Log errors if the platform does not supply logging macros.
35  */
36 
37 #ifndef CHPP_LOGE
38 #error "CHPP_LOGE must be defined"
39 #endif  // CHPP_LOGE
40 
41 #ifndef CHPP_LOGW
42 #error "CHPP_LOGW must be defined"
43 #endif  // CHPP_LOGW
44 
45 #ifndef CHPP_LOGI
46 #error "CHPP_LOGI must be defined"
47 #endif  // CHPP_LOGI
48 
49 #ifndef CHPP_LOGD
50 #error "CHPP_LOGD must be defined"
51 #endif  // CHPP_LOGD
52 
53 #ifndef CHPP_MINIMUM_LOG_LEVEL
54 #define CHPP_MINIMUM_LOG_LEVEL CHRE_LOG_LEVEL_DEBUG
55 #endif  // CHPP_MINIMUM_LOG_LEVEL
56 
57 #if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_ERROR
58 #undef CHPP_LOGE
59 #define CHPP_LOGE(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
60 #endif
61 
62 #if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_WARN
63 #undef CHPP_LOGW
64 #define CHPP_LOGW(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
65 #endif
66 
67 #if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_INFO
68 #undef CHPP_LOGI
69 #define CHPP_LOGI(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
70 #endif
71 
72 #if CHPP_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_DEBUG
73 #undef CHPP_LOGD
74 #define CHPP_LOGD(format, ...) CHRE_LOG_NULL(format, ##__VA_ARGS__)
75 #endif
76 
77 /**
78  * Logs an out of memory error with file and line number.
79  */
80 #define CHPP_LOG_OOM() CHPP_LOGE("OOM at %s:%d", __FILE__, __LINE__)
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif  // CHPP_LOG_H_
87