• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LINUX_LOG_H_
18 #define CHRE_PLATFORM_LINUX_LOG_H_
19 
20 #include "chre_api/chre/re.h"
21 
22 #ifndef __FILENAME__
23 #define __FILENAME__ __FILE__
24 #endif
25 
26 #ifdef GTEST
27 // When using GoogleTest, just output to stdout since tests are single-threaded.
28 // GoogleTest complains about multiple threads if the PlatformLogSingleton is
29 // used.
30 #include <stdio.h>
31 
32 #define CHRE_LINUX_LOG(logLevel, levelStr, color, fmt, ...)               \
33   printf("\e[" color "m%s %s:%d\t" fmt "\e[0m\n", levelStr, __FILENAME__, \
34          __LINE__, ##__VA_ARGS__)
35 #else
36 #include "chre/platform/linux/platform_log.h"
37 
38 #define CHRE_LINUX_LOG(logLevel, levelStr, color, fmt, ...)        \
39   if (::chre::PlatformLogSingleton::isInitialized()) {             \
40     ::chre::PlatformLogSingleton::get()->log(                      \
41         logLevel, "\e[" color "m%s %s:%d\t" fmt "\e[0m", levelStr, \
42         __FILENAME__, __LINE__, ##__VA_ARGS__);                    \
43   }
44 #endif
45 
46 #define LOGE(fmt, ...) \
47   CHRE_LINUX_LOG(CHRE_LOG_ERROR, "E", "91", fmt, ##__VA_ARGS__)
48 #define LOGW(fmt, ...) \
49   CHRE_LINUX_LOG(CHRE_LOG_WARN, "W", "93", fmt, ##__VA_ARGS__)
50 #define LOGI(fmt, ...) \
51   CHRE_LINUX_LOG(CHRE_LOG_INFO, "I", "96", fmt, ##__VA_ARGS__)
52 #define LOGD(fmt, ...) \
53   CHRE_LINUX_LOG(CHRE_LOG_DEBUG, "D", "97", fmt, ##__VA_ARGS__)
54 
55 #endif  // CHRE_PLATFORM_LINUX_LOG_H_
56