Skip to content
Tony Trinh edited this page May 8, 2013 · 18 revisions

What's the difference between logback and logback-android?

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

The classpath-multiplicity warning (seen when multiple resources for the requested class exist on the classpath) is removed in logback-android to improve initialization performance and reduce the jar size.

Why would I use logback-android when I can use os.android.Log?

logback-android includes the same features as os.android.Log via LogcatAppender, but can do much more. For instance, logback-android supports several different types of log destination, including files and sockets, that can be configured by an external XML file after deployment.

What is the versioning scheme in logback-android?

x.x.x-N

where x.x.x is the version of logback proper from which this version of logback-android is based; and N is an integer, starting from 1 and incremented with each release.

For example, logback-android-1.0.6-1 and logback-android-1.0.6-2 are based on logback-1.0.6.

Why isn't logback-android at the same version level as logback?

I try to keep them in sync as much as possible, but schedules can slip (sorry).

How do I contribute?

Feel free to submit a pull request.

Where do I report issues? JIRA or GitHub?

I prefer JIRA, but you can use either for now. I'll probably migrate completely to JIRA at some point.

Why isn't logback-android printing any messages at initialization even when I've intentionally added syntax errors?

It sounds like logback-android can't see your file. To troubleshoot the problem, turn on debugging by setting the debug flag in:

<configuration debug='true'>
  ...
</configuration>

This flag causes configuration logs to show in real-time.

When does logback.xml actually get read from my application?

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).

Why do I get NetworkOnMainThreadException when I use SocketAppender or SyslogAppender?

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).

Why doesn't my FileAppender (or RollingFileAppender) write to the specified location?

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.

Why won't my ConsoleAppender output to logcat?

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.

Why won't my SMTPAppender send email?

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.

Why can't I step through logback-android code?

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.