1 /* 2 * Copyright (C) 2016 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 CHRE_PLATFORM_LOG_H_ 18 #define CHRE_PLATFORM_LOG_H_ 19 20 /** 21 * @file 22 * Includes the appropriate platform-specific header file that supplies logging 23 * capabilities. The platform header file must supply these symbols, either as 24 * macros or free functions: 25 * 26 * LOGE(format, ...) 27 * LOGW(format, ...) 28 * LOGI(format, ...) 29 * LOGD(format, ...) 30 * 31 * Where "format" is a printf-style format string, and E, W, I, D correspond to 32 * the log levels Error, Warning, Informational, and Debug, respectively. 33 */ 34 35 #include "chre/target_platform/log.h" 36 #include "chre/util/log_common.h" 37 38 /* 39 * Log errors if the platform does not supply logging macros. 40 */ 41 42 #ifndef LOGE 43 #error "LOGE must be defined" 44 #endif // LOGE 45 46 #ifndef LOGW 47 #error "LOGW must be defined" 48 #endif // LOGW 49 50 #ifndef LOGI 51 #error "LOGI must be defined" 52 #endif // LOGI 53 54 #ifndef LOGD 55 #error "LOGD must be defined" 56 #endif // LOGD 57 58 /* 59 * Supply a stub implementation of the LOGx macros when the build is 60 * configured with a minimum logging level that is above the requested level. 61 */ 62 63 #ifndef CHRE_MINIMUM_LOG_LEVEL 64 #error "CHRE_MINIMUM_LOG_LEVEL must be defined" 65 #endif // CHRE_MINIMUM_LOG_LEVEL 66 67 #if CHRE_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_ERROR 68 #undef LOGE 69 #define LOGE(format, ...) chreLogNull(format, ##__VA_ARGS__) 70 #endif 71 72 #if CHRE_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_WARN 73 #undef LOGW 74 #define LOGW(format, ...) chreLogNull(format, ##__VA_ARGS__) 75 #endif 76 77 #if CHRE_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_INFO 78 #undef LOGI 79 #define LOGI(format, ...) chreLogNull(format, ##__VA_ARGS__) 80 #endif 81 82 #if CHRE_MINIMUM_LOG_LEVEL < CHRE_LOG_LEVEL_DEBUG 83 #undef LOGD 84 #define LOGD(format, ...) chreLogNull(format, ##__VA_ARGS__) 85 #endif 86 87 /** 88 * Logs an out of memory error with file and line number. 89 */ 90 #define LOG_OOM() LOGE("OOM at %s:%d", CHRE_FILENAME, __LINE__) 91 92 #endif // CHRE_PLATFORM_LOG_H_ 93