首頁>Club>
14
回覆列表
  • 1 # 小玲子Z

    檢視方法:

      一、在 Java 與 C 語言中輸出日誌:

    1) Java 程式碼在程式中輸出日誌, 使用 android.util.Log 類的以下 5 個方法:

       Log.v()、Log.d()、Log.i()、Log.w()、Log.e()。

       分對應 Verbose、Debug、INFO、Warn、Error 的首字母。

       例如:Log.i( "類::函式名", "日期_時間_原始碼檔名_行號_日誌資訊內容" );

      2) C 程式碼在程式中輸出日誌,使用 log 的 API 函式:

       __android_log_write( 日誌型別宏,日誌標籤字串,日誌令牌內容字串 );

       需要:1. Android.mk 中新增 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog

          2. *.c 中新增 #include <android/log.h>

          3. 日誌型別宏有:


      複製程式碼 程式碼如下:


            // Android log priority values, in ascending priority order.

            typedef enum android_LogPriority {

                ANDROID_LOG_UNKNOWN = 0,

                // only for SetMinPriority() 

                ANDROID_LOG_DEFAULT,

                ANDROID_LOG_VERBOSE,

                ANDROID_LOG_DEBUG,

                ANDROID_LOG_INFO,

                ANDROID_LOG_WARN,

                ANDROID_LOG_ERROR,

                ANDROID_LOG_FATAL,

                // only for SetMinPriority(); must be last 

                ANDROID_LOG_SILENT,

            } android_LogPriority;


    二、logcat 使用方法:      

    Usage: logcat [options] [filterspecs]

    用法: logcat [選項] [過濾說明]


      options include:

    選項包含:

      -s Set default filter to silent.

                      Like specifying filterspec '*:S'

                      設定預設過濾為無聲的。

                      像指定過濾說明為 *:S ,見下面 過濾說明 部份詳述


      -f <filename> Log to file. 

                      Default to stdout

                      輸出日誌到檔案。

                      預設為 stdout 


      -r [<kbytes>] Rotate log every kbytes. 

                      (16 if unspecified). 

                      Requires -f

                      設定環形日誌緩衝區的kbytes。

                      預設值為16。

                      需要和 -f 選項一起使用


      -n <count> Sets max number of rotated logs to <count>, default 4

                      設定環形日誌緩衝區的最大數目,預設值是4,需要和 -r 選項一起使用


      -v <format> Sets the log print format, where <format> is one of:

                      設定 log 的列印格式, 格式有如下主要7種:(不能組合使用)

      brief

                      process 

                      tag 

                      thread 

                      raw 

                      time 

                      threadtime 

                      long

      -c clear (flush) the entire log and exit

                      清除所有 log 並退出


      -d dump the log and then exit (don't block)

                      得到所有log並退出且不阻塞


      -t <count> print only the most recent <count> lines (implies -d)

                      僅列印最近的由引數 count 指出的行數(必然包含 -d)


      -g get the size of the log's ring buffer and exit

                      得到環形緩衝區的大小並退出


      -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio' or 'events'.

                      Multiple -b parameters are allowed and the results are interleaved. 

                      The default is -b main -b system.

                      請求供替換的環形緩衝區,如:main,system,radio,events。

                      多個 -b 引數是被允許,並且結果是交錯輸出的。

                      -b main -b system 是預設的。


      -B output the log in binary

                      輸出 log 到二進位制檔案中。


    filterspecs are a series of <tag>[:priority]

    過濾說明是一系列 <tag>[:priority]

      where <tag> is a log component tag (or * for all) and priority is:

    tag 是 eclipse 中 logcat 圖形介面中 Tag 的內容(或者有 * 表示全部),它之後的冒號(:)後面跟優先順序:

        日誌型別識別符號(優先順序由低到高排列):

        1. V — Verbose 詳細的 <- 最低優先權

        2. D — Debug 除錯

        3. I — Info 訊息

        4. W — Warn 警告

        5. E — Error 錯誤

        6. F — Fatal 致命的

        7. S — Silent 無聲的 <- 最高優先權

      '*' means '*:d' and <tag> by itself means <tag>:v

    * 意味著 *:d 且 單孤地 tag 意味著 tag:V

      If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.

    如果在命令列上沒有詳細說明,過濾規格即是 ANDROID_LOG_TAGS 結果集。

      If no filterspec is found, filter defaults to '*:I'

    如果沒有過濾說明,過濾規格預設為 *:I

      If not specified with -v, format is set from ANDROID_PRINTF_LOG or defaults to "brief"

    如果沒有 -v 指定格式,將是 ANDROID_PRINTF_LOG 或 brief 格式集。

      1) 只輸出指定 標籤 和 型別 的日誌

       格式:

       adb logcat <日誌標籤>:<日誌型別識別符號> <日誌標籤>:<日誌型別識別符號> ... *:S

       注:1. 可以寫多個 <日誌標籤>:<日誌型別識別符號> 之間用空格分隔;

         2. 最後必須是 *:S ,表示其它的都不要顯示出來

       例如:

       $ adb logcat dalvikvm:D Checkin:W *:S


       注:adb logcat Checkin *:S =等同於=> adb logcat Checkin:V *:S

       注:以上命令均沒加 -v 來指出日誌格式,即預設為: ANDROID_PRINTF_LOG 或 brief 格式集。

      2) 輸出指定 標籤 和 型別 的帶有格式的日誌

    注:以下測試日誌內容為:test log format,

      即 eclipse 中的 logcat 圖形介面裡的 Text 中的內容!

      1. brief - 日誌型別/日誌標籤(程序ID): 日誌內容

       例如:$ adb logcat -v brief Checkin *:S

          I/Checkin(24713): test log format


    2. process - 日誌型別(程序ID) 日誌內容 (日誌標籤)

       例如:$ adb logcat -v process Checkin *:S

          I(24713) test log format (Checkin)


    3. tag - 日誌型別/日誌標籤: 日誌內容

       例如:$ adb logcat -v tag Checkin *:S

            I/Checkin: test log format


    4. thread - 日誌型別(程序ID:執行緒ID)

       例如:$ adb logcat -v thread Checkin *:S

            I(24713:0x6089) test log format


    5. raw - 日誌內容

       例如:$ adb logcat -v raw Checkin *:S

            test log format


    6. time - 日期 呼叫時間 日誌型別/日誌標籤(程序ID): 日誌內容

       例如:$ adb logcat -v time Checkin *:S

       05-27 11:25:33.854 I/Checkin(24713): test log format

      7. threadtime - 日期 呼叫時間 程序ID 執行緒ID 日誌型別 日誌標籤: 日誌內容

       例如:$ adb logcat -v time Checkin *:S

       05-27 11:25:33.854 24713 24713 I Checkin: test log format

       注:只有此種格式時 執行緒ID 為十進位制數。


    8. long - [ 日期 呼叫時間 程序ID:執行緒ID 日誌型別/日誌標籤 ] 轉行顯示 日誌內容

       例如:$ adb logcat -v long Checkin *:S

       [ 05-27 11:25:33.854 24713:0x6089 I/Checkin ]

       test log format

  • 中秋節和大豐收的關聯?
  • 自己做針織批發,不懂網店,想入駐拼多多,能行嗎,求高人指點