Debugging KittyORM
By design KittyORM able to log to logstream quite a lot of information in order to make it easier to implement KittyORM database in your application. Right now KittyORM has three types of logs: base log that logs main information such as errors and bootstrap messages, query log that logs queries sent to be executed by SQLite and dex utility log that logs what happens when KittyORM registry created from package.
Logging can be enabled via KITTY_DATABASE
annotation. To do this, set up return values of isLoggingOn
, isProductionOn
, isKittyDexUtilLoggingEnabled
and logTag
of KITTY_DATABASE
annotation that annotates your KittyORM implementation database class.
1@KITTY_DATABASE(
2 isLoggingOn = true, // Base logging flag
3 isProductionOn = false, // Production logging flag
4 isKittyDexUtilLoggingEnabled = false, // dex logging flag
5 logTag = MigrationDBv3.LTAG, // log tag
6 databaseName = "mig", // database name
7 databaseVersion = 3, // database version
8 ...
9)
10
11public class MigrationDBv3 extends KittyDatabase {
12
13 public static final String LTAG = "MIGv3";
14
15 ...
16}
isLoggingOn
- main logging flag, by default - false. Setting this value to true would cause KittyORM log all errors, warnings and bootstrap info except log output of dex util and queries. When this value is false than no logging would be performed at all, even ifisProductionOn
flag is false andisKittyDexUtilLoggingEnabled
flag is true. Most log messages would contain specified log tag, database name and database version to make debugging easier.isProductionOn
- query logging, by default - true. When this value is false andisLoggingOn
is true - logs queries sent to be executed by SQLite to log stream. Be sure that you turn production mode on when you’re ready to publish your application because logging queries to log stream is a potential security vulnerability and may slow down KittyORM when, for example, you need to save a big amount of entities to database.isKittyDexUtilLoggingEnabled
- dex util logging flag, by default - false. When this value is true andisLoggingOn
is true - logs messages related with usage ofKittyDexUtils.class
. Actually, it is bag idea to generate KittyORM registry from package at production builds, because it causes slow initialization of KittyORM implementation, refer to Speed up your KittyORM article for more details.logTag
- log tag for all log messages related to this KittyORM database implementation. By default -"KittySQLiteORM"
.
Also, you may make your query log more informative by overloading String toLogString()
method of KittyModel.class
implementation to log update and insert queries. Example:
1@KITTY_TABLE
2public class SimpleExampleModel extends KittyModel {
3 public SimpleExampleModel() {
4 super();
5 }
6
7 @KITTY_COLUMN(
8 isIPK = true,
9 columnOrder = 0
10 )
11 public Long id;
12
13 @KITTY_COLUMN(columnOrder = 1)
14 public int randomInteger;
15
16 @KITTY_COLUMN(columnOrder = 2)
17 public String firstName;
18
19 @Override
20 public String toString() {
21 StringBuilder sb = new StringBuilder(64);
22 return sb.append("[ rowid = ")
23 .append(getRowID())
24 .append(" ; id = ")
25 .append(id)
26 .append(" ; randomInteger = ")
27 .append(randomInteger)
28 .append(" ; firstName = ")
29 .append(firstName)
30 .append(" ]")
31 .toString();
32 }
33
34 public String toLogString() {
35 return toString();
36 }
37}