-
-
Notifications
You must be signed in to change notification settings - Fork 174
logback-android
and logback
are fundamentally the same, except logback
proper uses language classes that are not available to Android; and thus those are either rewritten or ommitted. Plus, logback-android
has features that are specific to Android (e.g., LogcatAppender
).
Most (if not all) core features from logback
are carried over; but the following features are NOT supported in logback-android
:
logback-access
- Groovy configuration
- Janino configuration (conditionals in XML, etc.)
- JMS, JMX, JNDI, and Servlets
logback-android
includes the same features as os.android.Log
via LogcatAppender
, but can do much more.
The XML file at assets/logback.xml
is read on the first call to org.slf4j.LoggerFactory.getLogger(…)
from your application code. If it doesn't exist, logback-android
silently does nothing (and logging is disabled).
This exception indicates that these network-dependent appenders were invoked from the main thread (e.g., by logging statements) while your Android application has Strict Mode enabled. You can work around this by using these appenders via the AsyncAppender
, which calls the appenders asynchronously thereby avoiding the exception.
Why doesn't logback-android pick up the changes I just made to logback.xml
even after I restarted my app? Is auto-config broken?
Auto-configuration occurs only once at initialization when the first logger in your application is instantiated. Android doesn't necessarily end the application when it disappears from view. In order to restart the app (and thus reload the auto-config), you must first kill the app. You can use a TaskManager app or adb
(the kill
command).
Verify that you have write-permissions for the specified file location.
Make sure to specify the absolute path to a location that your application has write-permissions.
To write to the SD card, your application must have the WRITE_EXTERNAL_STORAGE
permission.
The LogcatAppender
is recommended over ConsoleAppender
, but you may still use the ConsoleAppender
if you wish.
The ConsoleAppender
writes to stdout, which is normally suppressed in devices (but is redirected by default in the emulator). The Android documentation provides instructions to redirect the output of stdout to logcat with priority INFO
. Also make sure your logcat filter allows the INFO
level.
Verify your application has the INTERNET
permission.
Verify you have the javamail-android
libraries in your application class path.
Double-check your logback-android
configuration. By default, SMTPAppender
buffers up 256 log entries and sends only ERROR
-level messages. So, you wouldn't see the email until you've logged at least 256 errors. This is meant to prevent flooding the recipient's inbox. You can change this threshold by setting the <cyclicBufferTracker>
property and by using a TriggerEvaluator
, as described in the user manual.
The logback-android
binaries are released without debug symbols to reduce the JAR size. You'll need to recompile with the debug profile (mvm -Pdebug package
) to get debug symbols and line information in order for breakpoints and stepping to work properly. You can also check the SNAPSHOTS
repository, which normally contains JARs built with the debug profile.