Code Monkey home page Code Monkey logo

log4j2-android's Introduction

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

  • Ensure that the dependency you provide for log4j2-android is runtime or its equivalent
  • Ensure that from the final deployment log4j-core library is excluded. log4j2-android is a functional replacement for log4j-core, including both might create unexpected behavior.
  • log4j2-android is a runtime library. Naturally, you do not need to modify your android code in any way. You just need to change the dependencies. If you are referencing the classes included in log4j2-android in your code, then there is a good chance that you are doing something wrong!

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.

log4j2-android's People

Contributors

243826 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tomek-sienicki

log4j2-android's Issues

log4j2.xml

where is log4j2.xml file in android project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.