[13] use of the injection framework roboguice: (logging via ln)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.