當前位置:編程學習大全網 - 源碼下載 - java的Thread中setPriority怎樣使用

java的Thread中setPriority怎樣使用

查看方法:

壹、在 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

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 Log to file.

Default to stdout

輸出日誌到文件。

默認為 stdout

-r [] Rotate log every kbytes.

(16 if unspecified).

Requires -f

設置環形日誌緩沖區的kbytes。

默認值為16。

需要和 -f 選項壹起使用

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

設置環形日誌緩沖區的最大數目,默認值是4,需要和 -r 選項壹起使用

-v Sets the log print format, where 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 print only the most recent lines (implies -d)

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

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

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

-b 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 [:priority]

過濾說明是壹系列 [:priority]

where 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 by itself means :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

  • 上一篇:如何使用springmvc攔截器
  • 下一篇:天貓、淘寶常用的網店管理軟體有哪些? 最好帶有售後管理功能的?
  • copyright 2024編程學習大全網