Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 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 // Logging
     18 
     19 // In order of decreasing priority, the log priority levels are:
     20 //    Assert
     21 //    E(rror)
     22 //    W(arn)
     23 //    I(nfo)
     24 //    D(ebug)
     25 //    V(erbose)
     26 // Debug and verbose are usually compiled out except during development.
     27 
     28 /** These values match the definitions in system/core/include/cutils/log.h */
     29 #define SLAndroidLogLevel_Unknown 0
     30 #define SLAndroidLogLevel_Default 1
     31 #define SLAndroidLogLevel_Verbose 2
     32 #define SLAndroidLogLevel_Debug   3
     33 #define SLAndroidLogLevel_Info    4
     34 #define SLAndroidLogLevel_Warn    5
     35 #define SLAndroidLogLevel_Error   6
     36 #define SLAndroidLogLevel_Fatal   7
     37 #define SLAndroidLogLevel_Silent  8
     38 
     39 // USE_LOG is the minimum log priority level that is enabled at build time.
     40 // It is configured in Android.mk but can be overridden per source file.
     41 #ifndef USE_LOG
     42 #define USE_LOG SLAndroidLogLevel_Info
     43 #endif
     44 
     45 
     46 #ifdef ANDROID
     47 
     48 // The usual Android LOGx macros are not available, so we use the lower-level APIs.
     49 extern const char slLogTag[];
     50 
     51 // can't disable SL_LOGF
     52 #define SL_LOGF(...) __android_log_print(SLAndroidLogLevel_Fatal, slLogTag, __VA_ARGS__)
     53 
     54 #if (USE_LOG <= SLAndroidLogLevel_Error)
     55 #define SL_LOGE(...) __android_log_print(SLAndroidLogLevel_Error, slLogTag, __VA_ARGS__)
     56 #else
     57 #define SL_LOGE(...) do { } while (0)
     58 #endif
     59 
     60 #if (USE_LOG <= SLAndroidLogLevel_Warn)
     61 #define SL_LOGW(...) __android_log_print(SLAndroidLogLevel_Warn, slLogTag, __VA_ARGS__)
     62 #else
     63 #define SL_LOGW(...) do { } while (0)
     64 #endif
     65 
     66 #if (USE_LOG <= SLAndroidLogLevel_Info)
     67 #define SL_LOGI(...) __android_log_print(SLAndroidLogLevel_Info, slLogTag, __VA_ARGS__)
     68 #else
     69 #define SL_LOGI(...) do { } while (0)
     70 #endif
     71 
     72 #if (USE_LOG <= SLAndroidLogLevel_Debug)
     73 #define SL_LOGD(...) __android_log_print(SLAndroidLogLevel_Debug, slLogTag, __VA_ARGS__)
     74 #else
     75 #define SL_LOGD(...) do { } while (0)
     76 #endif
     77 
     78 #if (USE_LOG <= SLAndroidLogLevel_Verbose)
     79 #define SL_LOGV(...) __android_log_print(SLAndroidLogLevel_Verbose, slLogTag, __VA_ARGS__)
     80 #else
     81 #define SL_LOGV(...) do { } while (0)
     82 #endif
     83 
     84 #else   // !defined(ANDROID)
     85 
     86 #if (USE_LOG <= SLAndroidLogLevel_Error)
     87 #define SL_LOGE(...) do { fprintf(stderr, "SL_LOGE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \
     88     fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0)
     89 #else
     90 #define SL_LOGE(...) do { } while (0)
     91 #endif
     92 
     93 #if (USE_LOG <= SLAndroidLogLevel_Warn)
     94 #define SL_LOGW(...) do { fprintf(stderr, "SL_LOGW: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \
     95     fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0)
     96 #else
     97 #define SL_LOGW(...) do { } while (0)
     98 #endif
     99 
    100 #if (USE_LOG <= SLAndroidLogLevel_Info)
    101 #define SL_LOGI(...) do { fprintf(stderr, "SL_LOGI: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \
    102     fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0)
    103 #else
    104 #define SL_LOGI(...) do { } while (0)
    105 #endif
    106 
    107 #if (USE_LOG <= SLAndroidLogLevel_Debug)
    108 #define SL_LOGD(...) do { fprintf(stderr, "SL_LOGD: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \
    109     fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0)
    110 #else
    111 #define SL_LOGD(...) do { } while (0)
    112 #endif
    113 
    114 #if (USE_LOG <= SLAndroidLogLevel_Verbose)
    115 #define SL_LOGV(...) do { fprintf(stderr, "SL_LOGV: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \
    116     fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0)
    117 #else
    118 #define SL_LOGV(...) do { } while (0)
    119 #endif
    120 
    121 #endif  // ANDROID
    122