log.h revision 61c5c1b001573d91012fd18e670e262b414aa81b
1/* 2 * Copyright (C) 2017 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_UTIL_NANOAPP_LOG_H_ 18#define CHRE_UTIL_NANOAPP_LOG_H_ 19 20/** 21 * @file 22 * Logging macros for nanoapps. These macros allow injecting a LOG_TAG and 23 * compiling nanoapps with a minimum logging level (that is different than CHRE 24 * itself). 25 * 26 * The typical format for the LOG_TAG macro is: "[AppName]" 27 */ 28 29#include "chre/util/log_common.h" 30 31#ifndef NANOAPP_MINIMUM_LOG_LEVEL 32#error "NANOAPP_MINIMUM_LOG_LEVEL must be defined" 33#endif // NANOAPP_MINIMUM_LOG_LEVEL 34 35/* 36 * Supply a stub implementation of the LOGx macros when the build is 37 * configured with a minimum logging level that is above the requested level. 38 * Otherwise just map into the chreLog function with the appropriate level. 39 */ 40 41#if NANOAPP_MINIMUM_LOG_LEVEL >= CHRE_LOG_LEVEL_ERROR 42#define LOGE(fmt, ...) chreLog(CHRE_LOG_ERROR, LOG_TAG " " fmt, ##__VA_ARGS__) 43#else 44#define LOGE(fmt, ...) chreLogNull(fmt, ##__VA_ARGS__) 45#endif 46 47#if NANOAPP_MINIMUM_LOG_LEVEL >= CHRE_LOG_LEVEL_WARN 48#define LOGW(fmt, ...) chreLog(CHRE_LOG_WARN, LOG_TAG " " fmt, ##__VA_ARGS__) 49#else 50#define LOGW(fmt, ...) chreLogNull(fmt, ##__VA_ARGS__) 51#endif 52 53#if NANOAPP_MINIMUM_LOG_LEVEL >= CHRE_LOG_LEVEL_INFO 54#define LOGI(fmt, ...) chreLog(CHRE_LOG_INFO, LOG_TAG " " fmt, ##__VA_ARGS__) 55#else 56#define LOGI(fmt, ...) chreLogNull(fmt, ##__VA_ARGS__) 57#endif 58 59#if NANOAPP_MINIMUM_LOG_LEVEL >= CHRE_LOG_LEVEL_DEBUG 60#define LOGD(fmt, ...) chreLog(CHRE_LOG_DEBUG, LOG_TAG " " fmt, ##__VA_ARGS__) 61#else 62#define LOGD(fmt, ...) chreLogNull(fmt, ##__VA_ARGS__) 63#endif 64 65// Apply printf-style compiler warnings to chreLog calls via GCC/clang 66#if defined(__GNUC__) || defined(__clang__) 67__attribute__((format(printf, 2, 3))) 68void chreLog(enum chreLogLevel level, const char *formatStr, ...); 69#endif 70 71#endif // CHRE_UTIL_NANOAPP_LOG_H_ 72