Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.anydo:logback-android:v_1.1.1-6-1'
}
dependencies {
implementation("com.github.anydo:logback-android:v_1.1.1-6-1")
}
<dependency>
<groupId>com.github.anydo</groupId>
<artifactId>logback-android</artifactId>
<version>v_1.1.1-6-1</version>
</dependency>
libraryDependencies += "com.github.anydo" % "logback-android" % "v_1.1.1-6-1"
:dependencies [[com.github.anydo/logback-android "v_1.1.1-6-1"]]
<sup>v1.1.1-6</sup>
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:
Runs on Android 2.1 or higher. See Wiki for documentation.
In app/build.gradle
, add the following dependencies:
// only needed for SNAPSHOT builds
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile('com.github.tony19:logback-android-classic:1.1.1-6') {
// workaround issue #73
exclude group: 'com.google.android', module: 'android'
}
}
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.
Gradle
// only needed for SNAPSHOT builds
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile 'com.github.tony19:logback-android-classic:1.1.1-6'
}
Prefer local jars?
logback-android
is built with Gradle 2.12. Use these commands to create the uber jar (with debug symbols).
git clone git://github.com/tony19/logback-android.git
cd logback-android
scripts/makejar.sh
The jar would be in: ./build/logback-android-1.1.1-6.jar