1a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten/* 2a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * Copyright (C) 2010 The Android Open Source Project 3a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * 4a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * Licensed under the Apache License, Version 2.0 (the "License"); 5a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * you may not use this file except in compliance with the License. 6a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * You may obtain a copy of the License at 7a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * 8a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * http://www.apache.org/licenses/LICENSE-2.0 9a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * 10a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * Unless required by applicable law or agreed to in writing, software 11a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * distributed under the License is distributed on an "AS IS" BASIS, 12a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * See the License for the specific language governing permissions and 14a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten * limitations under the License. 15a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten */ 16a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 17a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// Logging 18a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 19a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// In order of decreasing priority, the log priority levels are: 20a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// Assert 21a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// E(rror) 22a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// W(arn) 23a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// I(nfo) 24a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// D(ebug) 25a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// V(erbose) 26a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// Debug and verbose are usually compiled out except during development. 27a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 2847e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten/** These values match the definitions in system/core/include/cutils/log.h */ 2947e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Unknown 0 3047e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Default 1 3147e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Verbose 2 3247e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Debug 3 3347e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Info 4 3447e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Warn 5 3547e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Error 6 3647e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Fatal 7 3747e3a66decbf9fd9d33226b12d5c2d2d78e60343Glenn Kasten#define SLAndroidLogLevel_Silent 8 38a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 39a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// USE_LOG is the minimum log priority level that is enabled at build time. 40a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// It is configured in Android.mk but can be overridden per source file. 41a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#ifndef USE_LOG 42a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define USE_LOG SLAndroidLogLevel_Info 43a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 44a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 45a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 46a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#ifdef ANDROID 47a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 48a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten// The usual Android LOGx macros are not available, so we use the lower-level APIs. 49a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kastenextern const char slLogTag[]; 50a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 515cd605f62b687b22ff44a9de096b5f297eed74afGlenn Kasten// can't disable SL_LOGF 525cd605f62b687b22ff44a9de096b5f297eed74afGlenn Kasten#define SL_LOGF(...) __android_log_print(SLAndroidLogLevel_Fatal, slLogTag, __VA_ARGS__) 535cd605f62b687b22ff44a9de096b5f297eed74afGlenn Kasten 54a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Error) 55a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGE(...) __android_log_print(SLAndroidLogLevel_Error, slLogTag, __VA_ARGS__) 56a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 57a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGE(...) do { } while (0) 58a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 59a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 60a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Warn) 61a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGW(...) __android_log_print(SLAndroidLogLevel_Warn, slLogTag, __VA_ARGS__) 62a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 63a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGW(...) do { } while (0) 64a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 65a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 66a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Info) 67a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGI(...) __android_log_print(SLAndroidLogLevel_Info, slLogTag, __VA_ARGS__) 68a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 69a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGI(...) do { } while (0) 70a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 71a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 72a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Debug) 73a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGD(...) __android_log_print(SLAndroidLogLevel_Debug, slLogTag, __VA_ARGS__) 74a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 75a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGD(...) do { } while (0) 76a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 77a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 78a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Verbose) 79a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGV(...) __android_log_print(SLAndroidLogLevel_Verbose, slLogTag, __VA_ARGS__) 80a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 81a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGV(...) do { } while (0) 82a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 83a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 84a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else // !defined(ANDROID) 85a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 86a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Error) 87a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGE(...) do { fprintf(stderr, "SL_LOGE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 88a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 89a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 90a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGE(...) do { } while (0) 91a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 92a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 93a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Warn) 94a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGW(...) do { fprintf(stderr, "SL_LOGW: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 95a3080daa505f91df51a808c85ddb37c48745bf7cGlenn Kasten fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 96a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 97a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGW(...) do { } while (0) 98a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 99a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 100a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Info) 101a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGI(...) do { fprintf(stderr, "SL_LOGI: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 102a3080daa505f91df51a808c85ddb37c48745bf7cGlenn Kasten fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 103a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 104a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGI(...) do { } while (0) 105a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 106a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 107a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Debug) 108a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGD(...) do { fprintf(stderr, "SL_LOGD: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 109a3080daa505f91df51a808c85ddb37c48745bf7cGlenn Kasten fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 110a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 111a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGD(...) do { } while (0) 112a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 113a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 114a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#if (USE_LOG <= SLAndroidLogLevel_Verbose) 115a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGV(...) do { fprintf(stderr, "SL_LOGV: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 116a3080daa505f91df51a808c85ddb37c48745bf7cGlenn Kasten fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 117a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#else 118a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#define SL_LOGV(...) do { } while (0) 119a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif 120a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten 121a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten#endif // ANDROID 122