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/toolchain.h>
21
22 #include "chre/util/toolchain.h"
23
24 /**
25 * @file
26 * Includes common logging macros and functions that are shared between nanoapps
27 * and the CHRE implementation.
28 */
29
30 /**
31 * An inline stub function to direct log messages to when logging is disabled.
32 * This avoids unused variable warnings and will result in no overhead if
33 * passing the arguments doesn't have additional side effects.
34 */
35 CHRE_PRINTF_ATTR(1, 2)
chreLogNull(const char * fmt,...)36 static inline void chreLogNull(const char *fmt, ...) {
37 (void)fmt;
38 }
39
40 //! Macro version of chreLogNull that applies toolchain-specific preamble and
41 //! epilogue (e.g. to disable double promotion warnings)
42 #define CHRE_LOG_NULL(fmt, ...) \
43 do { \
44 CHRE_LOG_PREAMBLE \
45 chreLogNull(fmt, ##__VA_ARGS__); \
46 CHRE_LOG_EPILOGUE \
47 } while (0)
48
49 // Each log level below increases with value as verbosity increases, such that
50 // we can set a threshold for verbosity at compile time
51
52 //! Used with CHRE_MINIMUM_LOG_LEVEL to indicate that no logs should be included
53 #define CHRE_LOG_LEVEL_MUTE 0
54
55 #define CHRE_LOG_LEVEL_ERROR 1
56 #define CHRE_LOG_LEVEL_WARN 2
57 #define CHRE_LOG_LEVEL_INFO 3
58 #define CHRE_LOG_LEVEL_DEBUG 4
59 #define CHRE_LOG_LEVEL_VERBOSE 5
60
61 /**
62 * Logs an out of memory error with file and line number.
63 */
64 #define LOG_OOM() LOGE("OOM at %s:%d", CHRE_FILENAME, __LINE__)
65
66 #endif // CHRE_UTIL_LOG_COMMON_H_
67