• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
33  */
34 CHRE_PRINTF_ATTR(1, 2)
chreLogNull(const char * fmt,...)35 inline void chreLogNull(const char *fmt, ...) {
36   (void)fmt;
37 }
38 
39 //! Macro version of chreLogNull that applies toolchain-specific preamble and
40 //! epilogue (e.g. to disable double promotion warnings)
41 #define CHRE_LOG_NULL(fmt, ...)      \
42   do {                               \
43     CHRE_LOG_PREAMBLE                \
44     chreLogNull(fmt, ##__VA_ARGS__); \
45     CHRE_LOG_EPILOGUE                \
46   } while (0)
47 
48 // Each log level below increases with value as verbosity increases, such that
49 // we can set a threshold for verbosity at compile time
50 
51 //! Used with CHRE_MINIMUM_LOG_LEVEL to indicate that no logs should be included
52 #define CHRE_LOG_LEVEL_MUTE 0
53 
54 #define CHRE_LOG_LEVEL_ERROR 1
55 #define CHRE_LOG_LEVEL_WARN 2
56 #define CHRE_LOG_LEVEL_INFO 3
57 #define CHRE_LOG_LEVEL_DEBUG 4
58 #define CHRE_LOG_LEVEL_VERBOSE 5
59 
60 /**
61  * Logs an out of memory error with file and line number.
62  */
63 #define LOG_OOM() LOGE("OOM at %s:%d", CHRE_FILENAME, __LINE__)
64 
65 #endif  // CHRE_UTIL_LOG_COMMON_H_
66