SLF4J Android
The motivation for the SLF4J Android project was to ease using existing libraries which use SLF4J as their logging framework on the Google Android platform.
This project is basically a (i) repackaging of the SLF4J API part, together with (ii) a very lightweight binding implementation that simply forwards all SLF4J log requests to the logger provided on the Google Android platform. The API part is compiled from the same code basis of the standard distribution. This is the reason why we decided to keep the version numbering in sync with the standard SLF4J releases in order to reflect the code basis from which it was built.
Status
The implementation is currently fully functional but has not yet been fully tested in a production environment. Let us know if you have used it in production!
Usage
- Assuming that you use the Eclipse ADT plugin, simply add slf4j-android-<version>.jar to your project classpath.
- There is no further configuration required.
- Use loggers as usual:
-
Declare a logger
private static final Logger logger = LoggerFactory.getLogger(MyClass.class); - Invoke logging methods, e.g.,
logger.debug("Some log message. Details: {}", someObject.toString());
-
Declare a logger
Log level mapping
The following table shows the mapping from SLF4J log levels to log levels in the Android platform, implemented by the logger binding.
| SLF4J | Android |
|---|---|
| TRACE | VERBOSE |
| DEBUG | DEBUG |
| INFO | INFO |
| WARN | WARN |
| ERROR | ERROR |
Logger name mapping
Recap, Logger instances created using the LoggerFactory are named either according to the name given as parameter, or the fully qualified class name of the class given as paramenter. Each logger name will be used as the log message tag on the Android platform. However, the length of such tags is currently limited to 23 characters (23 = 32 - 8 for namespace prefix - 1 for C terminator). Starting from version 1.6.1, if the fully qualified class name (or the name given as parameter at creation time) exceeds this limit then it will be truncated by the LoggerFactory and the new Logger will have the truncated name. The following examples illustrate this.
| Original Name | Truncated Name |
|---|---|
| org.example.project.MyClass | o*.e*.p*.MyClass |
| org.example.project.subproject.MyClass | o*.e*.p*.s*.MyClass |
| org.example.MyQuiteLongNamedClassOfTooMuchCharacters | o*.e*.MyQuiteLongNamed* |
| o.e.project.subproject.MyClass | o.e.p*.s*.MyClass |
| MyQuiteLongNamedClassNotInAPackage | MyQuiteLongNamedClassN* |
Limitations
The Android binding implementation currently does not support Markers. All logging methods which have a Marker parameter simply delegate to the corresponding method without a Marker parameter, i.e., the Marker parameter is silently ignored.
Download
Release Candidate
Binary: slf4j-android-1.6.1-RC1.jar [sha1]
Source: slf4j-android-1.6.1-RC1-sources.jar [sha1]
Previous Version
Binary: slf4j-android-1.5.8.jar [sha1]
Source: slf4j-android-1.5.8-sources.jar [sha1]
Note that in version 1.5.8 logger names must not be longer than 23 characters, see
issue 173.
Source Repository
Sources are available read-only from the following Git repository, folder slf4j-android. This repository is a fork of the main SLF4J Git repository.
| Web access | http://github.com/twwwt/slf4j |
| git | git://github.com/twwwt/slf4j.git |
| http | http://github.com/twwwt/slf4j.git |
Credits
Created and maintained by Thorsten Möller, Databases and Information Systems Group – University of Basel – Switzerland
License
Source code and binaries are distributed under the MIT license.