Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-951

How to use log4j2 with Android (Logcat)?

    XMLWordPrintableJSON

Details

    • Question
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1
    • None
    • Appenders
    • Android

    Description

      This small Android project compiles using mvn clean install.

      It includes something like

          import org.apache.logging.log4j.LogManager;
          import org.apache.logging.log4j.Logger;
          // ...
          logger.info("=== Initialized ===");
      

      For configuring log4j2, I use a programmatically approch (see Log4jConfigure.java) to
      prevent the log4j2.xml Android issue as described in LOG4J2-728.

      But I didn't see my logging output on logcat.
      Seems that I need something like a LogcatAppender but couldn't find hints how to do that.

      I found this project but it has no commits over the last 2 years and so it seems that it not fits to log4j2.

      Seeing this output in logcat:

      ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

      A bit further investigation:

      • logging with logger.fatal() and logger.error() gave me output to logcat, but both with Level = Warning and Tag = System.err
      • all other logger.warn() ... logger.trace() were suppressed

      When checking the system property java.class.path, it returns ".", but this seems a normal circumstance (as described on developer.android.com).

      So falling back to the key questions: How to configure log4j2 properly to produce correct Android logcat output?

      • want to have the loglevel placed correctly
      • using the classname for the logcat tag seems a nice idea

      Could anybory help?

      Attachments

        Activity

          People

            Unassigned Unassigned
            FreeJoe Joe Merten
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: