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_LOG_COMMON_H_
18 #define CHRE_UTIL_LOG_COMMON_H_
19 
20 #include "chre/util/toolchain.h"
21 
22 /**
23  * @file
24  * Includes common logging macros and functions that are shared between nanoapps
25  * and the CHRE implementation.
26  */
27 
28 /**
29  * An inline stub function to direct log messages to when logging is disabled.
30  * This avoids unused variable warnings and will result in no overhead.
31  */
32 CHRE_PRINTF_ATTR(1, 2)
chreLogNull(const char * fmt,...)33 inline void chreLogNull(const char *fmt, ...) { (void) fmt; }
34 
35 //! Macro version of chreLogNull that applies toolchain-specific preamble and
36 //! epilogue (e.g. to disable double promotion warnings)
37 #define CHRE_LOG_NULL(fmt, ...) \
38     do { \
39       CHRE_LOG_PREAMBLE \
40       chreLogNull(fmt, ##__VA_ARGS__); \
41       CHRE_LOG_EPILOGUE \
42     } while (0)
43 
44 //! The logging level to specify that no logs are output.
45 #define CHRE_LOG_LEVEL_MUTE 0
46 
47 //! The logging level to specify that only LOGE is output.
48 #define CHRE_LOG_LEVEL_ERROR 1
49 
50 //! The logging level to specify that LOGW and LOGE are output.
51 #define CHRE_LOG_LEVEL_WARN 2
52 
53 //! The logging level to specify that LOGI, LOGW and LOGE are output.
54 #define CHRE_LOG_LEVEL_INFO 3
55 
56 //! The logging level to specify that LOGD, LOGI, LOGW and LOGE are output.
57 #define CHRE_LOG_LEVEL_DEBUG 4
58 
59 #endif  // CHRE_UTIL_LOG_COMMON_H_
60