Giter VIP home page Giter VIP logo

android-log4j2-support's Introduction

android-log4j2-support

This library adds the basic support for log4j-2.3 for Android. The libraries relying on log4j work on Android and Logcat appender is used to log their output.

Usage in Android applications

Setting up Gradle build

repositories {
    maven {
        url 'http://dev.atteq.com/maven2/'
    }
}

dependencies {
    compile 'com.atteq:android-log4j2-support:2.3'
}

Initialization of log4j

In the onCreate method of your application you may use the following code

AndroidLog4jHelper.initialise(getApplicationContext(), R.raw.log4j);

The contents of src/main/res/raw/log4j.xml then may look as follows.

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="debug">
    <Appenders>
        <Logcat name="Logcat">
            <ThresholdFilter
                level="ALL"
                onMatch="ACCEPT"
                onMismatch="DENY" />
            <PatternLayout pattern="%m" />
        </Logcat>
    </Appenders>

    <Loggers>
        <Root level="DEBUG">
            <AppenderRef ref="Logcat" />
        </Root>
    </Loggers>
</Configuration>

Using log4j

Finally you may use log4j as usual.

Logger.getLogger("org.apache").setLevel(Level.ERROR); // You would set this via config.
Logger.getLogger("my.fancy.logger").error("blaaah"); // You would normally use Log.e(...)

Credits

The code is highly inspired by https://loune.net/2016/05/using-log4j2-2-3-with-android/ and https://github.com/loune/log4j2-android. The main advantage is that the library can be simply added to Gradle and initialized in the application onCreate method.

android-log4j2-support's People

Contributors

babky avatar

Watchers

James Cloos avatar uchenp avatar

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.