Announcement Announcement Module
No announcement yet.
Android Commons Logging Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Android Commons Logging

    Looking at issue:

    ...does that mean there is no way the spring android commons logging module you provide will work?

    I can't see how it is possible to provide your own implementation of LogFactory in Android so that you can log to the android logging system?

    I've hit this problem from a different angle

  • #2
    sorry I hit send before I finished my post.

    I suppose it should be possible to provide a Log4j implementation that calls the android logging system and rely on the standard mechanism of LogFactoryImpl to detect Log4j (the new implementation)

    I am wondering what anyones thoughts are on the subject.



    • #3
      @paulf - Our motivation was simply to provide a wrapper around the Android logging so calls to commons logging would continue to work. You have pretty much summarized the problem. There is no official support from Android for commons logging, but any attempt to include your own version results in the ambiguous warnings you saw in the jira. Now that said, it does work, but because of the unsupported nature, future releases of Android might break this.

      Btw, there is already a project to provide the SLF4J wrapper you mentioned.


      • #4
        Hello Roy,

        Thanks for the reply. I must be missing something, how can it work if you cannot load your own org.apache.commons.logging.LogFactory class in Android?


        • #5
          Paul, we've decided to remove the spring-android-commons-logging library from the Spring Android M2 release, because of these issues with the private implementation in Android.

          What I found when I started working with the Maven Android Plugin, was that the commons logging worked without any additional code. The reason for this is that the project is compiled against the commons-logging-1.1.1.jar when using the Maven Android Plugin. Here's a bit from my first blog post about this:

          "Google prevented the official Android jars from being uploaded to Maven, so the, third party, Android for Maven project was started to provide an API compatible Android artifact that could be uploaded to the Maven repository. There are now artifacts for each major Android version available in the Maven repository. These are not functional, however, and only provide stubbed implementations of the API. All methods in all classes throw a runtime exception. Because an Android app runs on a device, it will never use these libraries for execution, but the API compatibility allows an app to be compiled as if it were the real library."

          The android dependency is marked as "provided" in the pom file when using the Maven Android Plugin, and the commons-logging jar as a transitive dependency is not being included in your application.

          I've put a very basic test project into the spring-mobile samples repository that illustrates working commons logging. Looking at logcat, you can see there are no warnings about duplicate class definitions, and that the Commons Logging calls are being logged to the Android log. So, there appears to be a working, private implementation in the real Android jar.

          $ git clone git:// spring-mobile-samples

          Look in the commons-logging-test directory for the project.

          This still leaves me with some questions about what's going on with the private implementation, and why Google wouldn't want to expose this functionality. I suspect they don't want logging heavy code running on mobile devices. I would also be hesitant to rely on this workaround too, since it is undocumented.


          • #6
            Cheers for that.

            I did some digging and it looks like Android provide a jdk 1.4 logger that commons logging will use that logs to the android log system.

            It has scuppered me since I actually wanted to re-direct the log statements to the OSGi log service which is our common running framework on android, windows mobile, PC etc etc

            Looks like a separate implemention is required in my case. Thanks for your help.