v2.0.0
logback-android
brings the power of logback
to Android. This library provides a highly configurable logging framework for Android apps, supporting multiple log destinations simultaneously:
- files
- SQLite databases
- logcat
- sockets
- syslog
Runs on Android 2.3 (SDK 9) or higher. See Wiki for documentation.
For v1.x
, see the 1.x
branch.
-
Create a new "Basic Activity" app in Android Studio.
-
In
app/build.gradle
, add the following dependencies:dependencies { compile 'org.slf4j:slf4j-api:1.7.25' compile 'com.github.tony19:logback-android:2.0.0' }
-
Create
app/src/main/assets/logback.xml
containing:<configuration> <appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender"> <tagEncoder> <pattern>%logger{12}</pattern> </tagEncoder> <encoder> <pattern>[%-20thread] %msg</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="logcat" /> </root> </configuration>
-
In
MainActivity.java
, add the following imports:import org.slf4j.Logger; import org.slf4j.LoggerFactory;
-
...and modify
onOptionsItemSelected()
to log "hello world":@Override public boolean onOptionsItemSelected(MenuItem item) { Logger log = LoggerFactory.getLogger(MainActivity.class); log.info("hello world"); // ... }
-
Build and start the app.
-
Open logcat for your device (via the Android Monitor tab in Android Studio).
-
Click the app menu, and select the menu-option. You should see "hello world" in logcat.
Gradle release
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'com.github.tony19:logback-android:2.0.0'
}
Gradle snapshot (unstable)
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'com.github.tony19:logback-android:2.0.1-SNAPSHOT'
}
Use these commands to create the AAR:
git clone git://github.com/tony19/logback-android.git
cd logback-android
scripts/makejar.sh
The file is output to: ./build/logback-android-2.0.0-debug.aar