首页 > 移动开发 > android使用orm框架ormlite在控制台打印log日志信息

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

在默认情况下,在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即可解决


本文固定链接: http://www.devba.com/index.php/archives/5286.html | 开发吧

报歉!评论已关闭.