<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                在前面的4.3小節中,我們介紹了Android系統運行時庫層的日志庫寫入接口,但是在實際開發中,我們一般不會直接使用這些接口來寫日志。在實際開發中,我們常常希望有些日志只在程序的調試版本中輸出,而不希望它們在發布版本中輸出。Android系統就提供了三組常用的C/C++宏來封裝日志寫入接口,這些宏有的在程序的非調試版本中只是一個空定義,因此,可以避免在程序的發布版本中輸出日志。 第一組宏是LOGV、LOGD、LOGI、LOGW和LOGE,它們用來寫入類型為main的日志記錄;第二組宏是SLOGV、SLOGD、SLOGI、SLOGW和SLOGE,它們用來寫入類型為system的日志記錄;第三組宏是LOG_EVENT_INT、LOG_EVENT_LONG和LOG_EVENT_STRING,它們用來寫入類型為events的日志記錄。這些宏定義在Android系統運行時庫層的一個頭文件log.h中,它的位置如下所示。 ~~~ ~/Android/system/core/include ----cutils ---- log.h ~~~ 這個頭文件定義了一個宏LOG_NDEBUG,用來區分程序是調試版本還是發布版本,如下所示。 **system/core/include/cutils/log.h** ~~~ /* * Normally we strip LOGV (VERBOSE messages) from release builds. * You can modify this (for example with "#define LOG_NDEBUG 0" * at the top of your source file) to change that behavior. */ #ifndef LOG_NDEBUG #ifdef NDEBUG #define LOG_NDEBUG 1 #else #define LOG_NDEBUG 0 #endif #endif ~~~ 在程序的發布版本中,宏LOG_NDEBUG定義為1,而在調試版本中定義為0。通過這個宏,我們就可以將某些日志宏在程序的發布版本中定義為空,從而限制它們在程序的發布版本中輸出。 這個頭文件還定義了宏LOG_TAG,用作當前編譯單元的默認日志記錄標簽,它的定義如下所示。 **system/core/include/cutils/log.h** ~~~ /* * This is the local tag used for the following simplified * logging macros. You can change this preprocessor definition * before using the other macros to change the tag. */ #ifndef LOG_TAG #define LOG_TAG NULL #endif ~~~ 它默認定義為NULL,即沒有日志記錄標簽。如果一個模塊想要定義自己的默認日志記錄標簽,那么就需要使用#define指令來自定義宏LOG_TAG的值。 了解了這兩個宏的定義之后,我們就開始分析這三組C/C++日志宏的實現。 **LOGV、LOGD、LOGI、LOGW和LOGE** **system/core/include/cutils/log.h** ~~~ /* * Simplified macro to send a verbose log message using the current LOG_TAG. */ #ifndef LOGV #if LOG_NDEBUG #define LOGV(...) ((void)0) #else #define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) #endif #endif /* * Simplified macro to send a debug log message using the current LOG_TAG. */ #ifndef LOGD #define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send an info log message using the current LOG_TAG. */ #ifndef LOGI #define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send a warning log message using the current LOG_TAG. */ #ifndef LOGW #define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send an error log message using the current LOG_TAG. */ #ifndef LOGE #define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) #endif ~~~ 這五個宏是用來寫入類型為main的日志記錄的,它們寫入的日志記錄的優先級分別為VERBOSE、DEBUG、INFO、WARN和ERROR。其中,宏LOGV只有在宏LOG_NDEBUG定義為0時,即在程序的調試版本中,才是有效的;否則,它只是一個空定義。 這五個宏是通過使用宏LOG來實現日志寫入功能的,它的定義如下所示。 **system/core/include/cutils/log.h** ~~~ /* * Basic log message macro. * * Example: * LOG(LOG_WARN, NULL, "Failed with error %d", errno); * * The second argument may be NULL or "" to indicate the "global" tag. */ #ifndef LOG #define LOG(priority, tag, ...) \ LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) #endif /* * Log macro that allows you to specify a number for the priority. */ #ifndef LOG_PRI #define LOG_PRI(priority, tag, ...) \ android_printLog(priority, tag, __VA_ARGS__) #endif #define android_printLog(prio, tag, fmt...) \ __android_log_print(prio, tag, fmt) ~~~ 當宏LOG展開后,它的第一個參數priority加上前綴“ANDROID_”之后,就變成了另外一個宏LOG_PRI的第一個參數。例如,宏LOGV展開后就得到宏LOG_PRI的第一個參數為ANDROID_LOG_VERBOSE。這些形式為ANDROID_##priority的參數都是類型為android_LogPriority的枚舉值,它們的定義如下所示。 **system/core/include/android/log.h** ~~~ /* * Android log priority values, in ascending priority order. */ typedef enum android_LogPriority { ANDROID_LOG_UNKNOWN = 0, ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ } android_LogPriority; ~~~ 回到宏LOG_PRI的定義中,它最終是通過調用日志庫liblog提供的函數__android_log_print向Logger日志驅動程序中寫入日志記錄的。函數__android_log_print的實現可以參考前面4.3小節的內容,這里不再詳述。 **SLOGV、SLOGD、SLOGI、SLOGW和SLOGE** **system/core/include/cutils/log.h** ~~~ /* * Simplified macro to send a verbose system log message using the current LOG_TAG. */ #ifndef SLOGV #if LOG_NDEBUG #define SLOGV(...) ((void)0) #else #define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) #endif #endif /* * Simplified macro to send a debug system log message using the current LOG_TAG. */ #ifndef SLOGD #define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send an info system log message using the current LOG_TAG. */ #ifndef SLOGI #define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send a warning system log message using the current LOG_TAG. */ #ifndef SLOGW #define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) #endif /* * Simplified macro to send an error system log message using the current LOG_TAG. */ #ifndef SLOGE #define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) #endif ~~~ 這五個宏是用來寫入類型為system的日志記錄的,它們寫入的日志記錄的優先級分別為VERBOSE、DEBUG、INFO、WARN和ERROR。其中,宏SLOGV只有在宏LOG_NDEBUG定義為0時,即在程序的調試版本中,才是有效的;否則,它只是一個空定義。 這五個宏展開之后,實際上是通過調用日志庫liblog提供的函數__android_log_buf_print向Logger日志驅動程序中寫入日志記錄的。函數__android_log_buf_print的實現可以參考前面4.3小節的內容,這里不再詳述。 **LOG_EVENT_INT、LOG_EVENT_LONG和LOG_EVENT_STRING** **system/core/include/cutils/log.h** ~~~ /* * Event log entry types. These must match up with the declarations in * java/android/android/util/EventLog.java. */ typedef enum { EVENT_TYPE_INT = 0, EVENT_TYPE_LONG = 1, EVENT_TYPE_STRING = 2, EVENT_TYPE_LIST = 3, } AndroidEventLogType; #define LOG_EVENT_INT(_tag, _value) { \ int intBuf = _value; \ (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \ sizeof(intBuf)); \ } #define LOG_EVENT_LONG(_tag, _value) { \ long long longBuf = _value; \ (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \ sizeof(longBuf)); \ } #define LOG_EVENT_STRING(_tag, _value) \ ((void) 0) /* not implemented -- must combine len with string */ /* TODO: something for LIST */ #define android_btWriteLog(tag, type, payload, len) \ __android_log_btwrite(tag, type, payload, len) ~~~ 這三個宏是用來寫入類型為events的日志記錄的。第6行到第9行首先定義了四個枚舉值,它們分別用來代表一個整數(int)、長整數(long)、字符串(string)和列表(list)。前面提到,類型為events的日志記錄的內容是由一系列值組成的,這些值是具有類型的,分別對應于EVENT_TYPE_INT、EVENT_TYPE_LONG、EVENT_TYPE_STRING和EVENT_TYPE_LIST四種類型。 宏LOG_EVENT_INT和LOG_EVENT_LONG寫入的日志記錄的內容分別是一個整數和一個長整數。它們展開之后,實際上是通過調用日志庫liblog提供的函數__android_log_btwrite來往Logger日志驅動程序中寫入日志記錄的。函數__android_log_btwrite的實現可以參考前面4.3小節的內容,這里不再詳述。 宏LOG_EVENT_STRING用來往Logger日志驅動程序中寫入一條內容為字符串值的日志記錄,但是在目前版本的實現中,它只是一個空定義。此外,在目前版本中,系統也沒有定義一個用來寫入內容為列表的日志記錄宏。因此,如果需要往Logger日志驅動程序中寫入一條內容為字符串或者列表的日志記錄,那么就必須直接使用日志庫liblog提供的函數__android_log_bwrite或者__android_log_btwrite。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看