In the previous article, we briefly introduced the use of roboguice ([12] injection framework roboguice usage: (your first injected contentprovider). Let's take a look at the usage of log.
The Android app prints log information on the android console using the built-in Android. util. log. Roboguice also provides additional log management, which you may want to use.
(1): roboguice log management is similar to common logs, but it also has the following advantages:
①: For release packages, the debug and verbose logs are automatically not displayed.
②: The application name, file, log line information, timestamp, thread, and other useful information will be automatically recorded (some information can be disabled to improve performance ). ③: Because variable parameters are used, disabling log display improves performance. If you often use DEBUG or verbose logging, this can improve performance.
④: You can overwrite formatted log messages where you want to use logs.
(2): some simple examples
Ln.v("hello there"); Ln.d("%s %s", "hello", "there"); // varargs Ln.e( exception, "Error during some operation"); // Throwables go at the FRONT! Ln.w( exception, "Error during %s operation", "some other"); Ln.v("hello there, ", "Mr. Invisible"); // ERROR, Mr. Invisible will never display
(3) Common traps
The syntax of LN and log is slightly different. Pay attention to the following points:
①: During the call, ensure that the exception information is added first. A common error is Android. util. Log conversion at the end, followed by varargs parameter.
②: Variable length parameters are not added to log messages. If you forget to insert % s or other parameters in similar formats to log messages, this parameter will be invalid.
(4): Changing log habits
Some apps may need to save logs to the default location instead of printing them directly on the android console. For example, you may need to save the log for Exception error analysis.
Therefore, you only need to implement the subclass of LN. print and bind it to the submodule. Note that ln does not perform log rollback. Therefore, when writing files, the storage space of the primary device is full. You can also rewrite the print method to output formatted logs. Remember that the print rewrite method is a global change, and the code of the task dependent on the ln log will use this print method.
[13] use of the injection framework roboguice: (logging via ln)