-
Notifications
You must be signed in to change notification settings - Fork 824
Logging via Ln
Android applications typically use the built-in android.util.Log
facility to log information to the android console. RoboGuice provides an alternate logger which you may want to consider using.
RoboGuice's Ln logger is similar to Log, but has the following advantages:
- Debug and verbose logging are automatically disabled for release builds.
- Your app name, file and line of the log message, time stamp, thread, and other useful information is automatically logged for you. (Some of this information is disabled for release builds to improve performance).
- Performance of disabled logging is faster than Log due to the use of the varargs. Since your most expensive logging will often be debug or verbose logging, this can lead to a minor performance win.
- You can override where the logs are written to and the format of the logging.
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
Ln's syntax is slightly different than Log's. Be aware of the following:
- Make sure you put the exception FIRST in the call. A common mistake is to place it last as is the android.util.Log convention, but then it will get treated as varargs parameter.
- vararg parameters are not appended to the log message! You must insert them into the log message using %s or another similar format parameter. If you forget, the parameter will be dropped.
Some apps may want to consider logging to alternate locations than the default android console. For example, you might want to log a copy of all log statements to a file for easy crash reporting.
To do this, simply implement a subclass of Ln.Print
and make sure to bind your subclass in your module implementation.
Be aware that Ln
does not do any log rolling for you, so be careful not to accidentally fill up your device's memory if you write to a file!
You can also override Print to change the format of the logging.
Be aware that overriding Print is a vm-wide change! Any other code that relies on Ln logging (which is likely RoboGuice, your own app, and any libraries that depend on RoboGuice) will also use your alternate Print.
- For Projects Using Gradle
- For Projects Using Maven
- Manual Installation for Older Projects
- Inheriting from RoboGuice Classes
- Upgrade Instructions from RoboGuice 2
- Your First View Injection
- Your First Resource Injection
- Your First System Service Injection
- Your First POJO Injection
- Singletons and ContextSingletons (wiki/Understanding Scopes)
- Your First Custom Binding
- Your First Injected Fragment
- Your First Injected Service and BroadcastReceiver
- Your First Testcase
- Your First Injection into a Custom View class
- Your First Injected ContentProvider
- Using Events in your RoboGuice application
- Logging via Ln
- RoboGuice Standard Injections
- How Injection Works
- When Injection Just Works, and when you have to call injectMembers()
- The Difference between Global and Context-scoped Injection
- Analyzing a Guice Stack Trace
- What's the difference between Nullable and Optional?
- RoboBlender wiki
- Use ProGuard with RoboGuice
- Define advanced custom bindings
- Remove or replace RoboGuice's default bindings
- Use your own BaseActivity with RoboGuice
- Inject into an object that you don't instantiate
- Dealing with Circular Dependencies
- Work with Library Projects
- Deal with ComputationException due to StackOverflowError
- Taming Fragmentation using RoboGuice