When using Kermit for logging, I see a crash when ...
# touchlab-tools
l
When using Kermit for logging, I see a crash when running tests on Android, saying that Log is not mocked. To fix this, I add the code below to every test class. Is there something I can do in Kermit to force it to use the Android writer when running the actual app, and the common writer in tests, or do I need to have the workaround every time?
Copy code
@BeforeTest
    fun setup() {
        Logger.setLogWriters(CommonWriter())
    }
r
I don't think we have anything that will do that automatically out of the box. We more often try to inject our logger instance, which still requires you to do something per-test but when it's required by the object you're testing then you don't forget it.
l
Yeah. The biggest issue right now is forgetting it. Is there a way for Kermit to check if it’s running in Android unit test, and set the logger, or is that out of scope for the library?
I could see an argument that an ‘Android’ logger should handle different cases within Android, but I can also see that being out of scope. Not sure where the responsibility of checking for unit tests should lie.
r
It's not the sort of thing I usually think of as within scope for a library like this, but since we have a static
Logger
config I could see an argument for it. Feel free to toss up a ticket if you want but I don't think we'll have time to think about it any time soon.
l
Perhaps a LogcatWriter + AndroidWriter would be appropriate? Have LogcatWriter write just to LogCat and AndroidWriter handle this?