Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android使用orm框架ormlite在控制台打印log日志信息

android使用orm框架ormlite在控制台打印log日志信息

編輯:關於Android編程

在默認情況下,在android下默認只打印info級別的日志信息,所以在默認情況只能打印ormlite中創建數據庫表的語句,而對於數據的插入和查詢等sql語句是不會打印出來的。在ormlite中提供了 AndroidLog類來設置adb log的級別。因為我們需要打印出更多的sql語句,這樣方便我們進行調試。

官網上是這樣說明的:

The ormlite-android.jar classes de ne the AndroidLog class which is the Android
speci c version of ORMLite logging. This class makes calls to the Log.d, Log.i, . . .
methods in the Android API. To see the log output, you will need to use the adb utility to
view the log output:
adb logcat
Since INFO is the default under Android, only message such as the following will be spit
out by default:
I/TableUtils( 254): creating table 'simpledata'
I/TableUtils( 254): creating index 'simpledata_string_idx' for table
'simpledata
I/TableUtils( 254): executed create table statement changed 1 rows:
CREATE TABLE `simpledata` (`date` VARCHAR, `id` INTEGER PRIMARY
KEY AUTOINCREMENT , `even` SMALLINT )
I/TableUtils( 254): executed create table statement changed 1 rows:
CREATE INDEX `simpledata_string_idx` ON `simpledata` ( `string` )
To enable more debug information you will want to do something like the following to
turn on logging for a particular class:
adb shell setprop log.tag.StatementExecutor VERBOSE
adb shell setprop log.tag.BaseMappedStatement VERBOSE
adb shell setprop log.tag.MappedCreate VERBOSE
This enables messages such as:
D/BaseMappedStatement(465): create object using 'INSERT INTO `simpledata`
(`date` ,`string` ,`millis` ,`even` ) VALUES (?,?,?,?)' and 4 args,
changed 1 rows
D/BaseMappedStatement(465): assigned id '9' from keyholder to 'id' in
SimpleData object
To enable all debug messages for all ORMLite classes then use the following:
adb shell setprop log.tag.ORMLite DEBUG
NOTE: Unfortunately, Android property names are limited in size so the ORMLite logger
only takes that last 23 [sic] characters of the class name if it is larger than 23 characters.
For example, if the class is AndroidDatabaseConnection you would do:
adb shell setprop log.tag.droidDatabaseConnection VERBOSE
If you are trying to track operations performed to the database by ORMLite use:
adb shell setprop log.tag.droidDatabaseConnection VERBOSE
adb shell setprop log.tag.ndroidCompiledStatement VERBOSE

也就是說要在後台打印輸出更多的日志信息,在項目啟動的過程中在adb控制台輸入:adb shell setprop log.tag.ORMLite DEBUG即可解決


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved