Celeral / log4j2-android

Use log4j2 logger with Android projects
Apache License 2.0
6 stars 1 forks source link
android log4j2 logcat logging

log4j2-android

Master Build Status Maven Central Javadoc Sonatype Nexus (Snapshots)

Use log4j2 API within your Android projects instead of Android's Log API. A nice side effect is that log4j2 logger in dependencies also work seamlessly on Android as it does in non-android projects.

Special Attention

TLDR? - I distilled the above points in the following build.gradle snippet and use it in my Android project so that I am able to automatically switch between log4j-core for logging during junit testing, and log4j2-android for logging on Android devices (testing or production) without modifying the build.gradle.

configurations.all {
    config -> {
        if (config.name.startsWith("test") || config.name.contains("Test") && !config.name.contains("Android")) {
            exclude group: "com.celeral", module: "log4j2-android"
        } else {
            exclude group:"org.apache.logging.log4j", module:"log4j-core"
        }
    }
    resolutionStrategy {
        force "org.apache.logging.log4j:log4j-api:2.17.2"
    }
}

dependencies {
    implementation "org.apache.logging.log4j:log4j-api:2.17.2"
    testRuntimeOnly "org.apache.logging.log4j:log4j-core:2.17.2"
    runtimeOnly "com.celeral:log4j2-android:1.0.0"
}

Get it!

Functionality of this package is contained in Java package com.celeral.android.logging.log4j2

Gradle

To use the package, you need to use the following gradle dependency. Note the scope being runtime since it's a runtime dependency:

dependencies {
  runtimeOnly 'com.celeral:log4j2-android:1.0.0'
}

Maven

To use the package, you need to use following Maven dependency. Note the scope being runtime since it's a runtime dependency:

<properties>
  ...
  <!-- Use the latest version whenever possible. -->
  <celeral.version.log4j2.android>1.0.0</celeral.version.log4j2.android>
  ...
</properties>

<dependencies>
  ...
  <dependency>
    <groupId>com.celeral</groupId>
    <artifactId>log4j2-android</artifactId>
    <version>${celeral.version.log4j2.android}</version>
    <scope>runtime</scope>
  </dependency>
  ...
</dependencies>

or download jars from Central Maven repository.

Non-Maven

For non-Maven use cases, you download jars from Central Maven repository.