Android-cleanarchitecture: How to log domain module?

Created on 15 Jun 2016  Â·  2Comments  Â·  Source: android10/Android-CleanArchitecture

I use android.util.Log class for logging and debugging my code, so I end up with an Android dependency inside the domain module. This is a problem when it comes to unit testing because I have to mock the static methods of this class using PowerMock, which in my case it increases code complexity unnecessarily.

Is there any other option to log the domain module without having to mock the logger for the tests?

discussion question

Most helpful comment

You can always use System.out.println() to avoid Android dependency.

Or, my prefered way, you can define a interface of your logger, providing it from the presentation layer with dagger, and then just inject that interface inside the domain class.

All 2 comments

I use slf4j for logging in every module and just place right implementation for each of them.
For example:
data — slf4j api with slf4j-android implementation
domain — slf4j api with logback implementation
presentation — slf4j api with slf4j-android implementation

You can always use System.out.println() to avoid Android dependency.

Or, my prefered way, you can define a interface of your logger, providing it from the presentation layer with dagger, and then just inject that interface inside the domain class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donlucard picture donlucard  Â·  3Comments

StreetFlaneur picture StreetFlaneur  Â·  3Comments

rshah picture rshah  Â·  6Comments

StuStirling picture StuStirling  Â·  3Comments

ashraffouad picture ashraffouad  Â·  5Comments