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 21 #ifndef __FILENAME__ 22 #define __FILENAME__ __FILE__ 23 #endif 24 25 #ifdef GTEST 26 // When using GoogleTest, just output to stdout since tests are single-threaded. 27 // GoogleTest complains about multiple threads if the PlatformLogSingleton is 28 // used. 29 #include <stdio.h> 30 31 #define CHRE_LINUX_LOG(level, color, fmt, ...) \ 32 printf("\e[" color "m%s %s:%d\t" fmt "\e[0m\n", \ 33 level, __FILENAME__, __LINE__, ##__VA_ARGS__) 34 #else 35 #include "chre/platform/shared/platform_log.h" 36 37 #define CHRE_LINUX_LOG(level, color, fmt, ...) \ 38 ::chre::PlatformLogSingleton::get()->log( \ 39 "\e[" color "m%s %s:%d\t" fmt "\e[0m", \ 40 level, __FILENAME__, __LINE__, ##__VA_ARGS__) 41 #endif 42 43 #define LOGE(fmt, ...) CHRE_LINUX_LOG("E", "91", fmt, ##__VA_ARGS__) 44 #define LOGW(fmt, ...) CHRE_LINUX_LOG("W", "93", fmt, ##__VA_ARGS__) 45 #define LOGI(fmt, ...) CHRE_LINUX_LOG("I", "96", fmt, ##__VA_ARGS__) 46 #define LOGD(fmt, ...) CHRE_LINUX_LOG("D", "97", fmt, ##__VA_ARGS__) 47 48 #endif // CHRE_PLATFORM_LINUX_LOG_H_ 49