How to manger log in different layers ?
In presentation layer, it is an Android module, then common logger can be applied, like https://github.com/orhanobut/logger In domain layer, if I understand well, it is almost a pure java module, so I cannot use the same logger as in presentation layer which has an android module logger. It means, I should use two different loggers in one project, then how to manager the logger in domain layer?
I have the same question. @nicolas2lee , did you find the correct way to do it?
@nicolas2lee I could be totally wrong in my approach to this, but I would not be that dogmatic with the structure. I would put the logger dependency in the domain layer, as long as your log calls don't effect your ability to unite test, which they should not. I would love to hear other peoples view on this though. Another possible option, that I have not tried, but I've heard is a good practice in the case of logging, is using an AOP (Aspect Oriented Programming) library to handle logging, since that is something you'll probibly need in a lot of sections of your code. And your last option... which I use in an app I wrote is defining an abstract default observer that has a base onError() function, and all of my use cases use that observer. When an error is triggered in the domain or data layers, assuming it happens in an Rx stream it will get passed up to the presentation layer and then you can handle the logging in the base on error method. I use Crashlytics.log() for that in my app. this is what that class looks like:
public class DefaultObserver<T> extends DisposableObserver<T> {
@Override public void onNext(T t) {
// no-op by default.
}
@Override public void onComplete() {
// no-op by default.
}
@Override public void onError(Throwable exception) {
// no-op by default.
Logger.e(exception,"");
Crashlytics.logException(exception);
}
}
You could always define that class as abstract if you want to force your sub-classes to implement any of the methods. I just chose not to. I hope that helps.