views:

74

answers:

2

I have a pretty big library I developed specifically for use in my Android Application. However business logic itself has no dependency on Android. To preserve that, I used Commons Logging throughout this library and it's respective JUnit tests (which I run in Eclipse).

However now that I am starting to integrate it into an Activity which I launch on Android, I am unable to get my logging to work. In Eclipse/JUnit, I had simply pulled in log4j's jar file as well as a log4j.properties file. This doesn't seem to work when deploying to a device. After struggling with attempting to get that to work for several hours, I gave up and tried replacing all my commons logging stuff with android.util.Log. Now I can log on the device.. but all JUnit tests are broken. When any JUnit tries to log using android.util.Log, it throws a RuntimeException 'Stub!'.

I would prefer to revert to my commons logging approach.. if anyone can help with that.. otherwise.. what can I do to get my JUnit test cases running using 'android.util.Log'?

Many thanks in advance.. I've spent more than a few hours on this and I'd like to move on to writing real code again!

+1  A: 

I don't believe there is a log4j port for android atm. However, android does have java.util.logging built in and commons logging can connect to that via the Jdk14Logger. If commons logging works on android then you'll probably be good to go.

Qberticus
A: 

You could build an Interface for your own logger that depending on the platform instantiates a delegate to the logging that is common on the platform. As long as you are working and debugging this should be enough, later in production code on the device you can simply insert a logger that does nothing and you save all the time you need to clutter the phonelog.

Janusz