touchlab / Kermit

Kermit by Touchlab is a Kotlin Multiplatform centralized logging utility.
https://kermit.touchlab.co
Apache License 2.0
699 stars 40 forks source link

Logger default arguments not usable in non-Kotlin and non-Java code #363

Closed jeffdgr8 closed 1 year ago

jeffdgr8 commented 1 year ago

When using a Logger class from Swift (and likely other non-Kotlin and non-Java languages, where Kotlin default arguments are not supported and @JvmOverloads doesn't apply), it's not possible to call any of the Logger functions that take default arguments without explicitly providing the tag and throwable arguments. This used to be possible before #328 introduced these default arguments. It would be preferable to explicitly provide these function overloads, rather than relying on Kotlin's default arguments, which currently lack multiplatform support.

kpgalligan commented 1 year ago

That is what https://github.com/touchlab/Kermit/tree/main/kermit-simple is for. Export that to non-kotlin clients.

Also, without spoiling anything, keep an eye on our announcements for the next couple weeks.

jeffdgr8 commented 1 year ago

Export that to non-kotlin clients.

How should this be done? I currently have:

val commonMain by getting {
    dependencies { 
        api("co.touchlab:kermit:2.0.0-RC5")
    }
}

I tried adding:

val iosMain by getting {
    dependencies {
        api("co.touchlab:kermit-simple:2.0.0-RC5")
    }
}

But the type is still KermitLogger : Kermit_coreBaseLogger in my exported framework.

keep an eye on our announcements for the next couple weeks.

Will do!

jeffdgr8 commented 1 year ago

Looks like ~I'd need to make it an implementation dependency in commonMain. But if I need the Logger part of the public API for Kotlin platforms, then do I need to add it explicitly as api in each of those targets?~

val androidMain by getting {
    dependencies { 
        api("co.touchlab:kermit:2.0.0-RC5")
    }
}
jeffdgr8 commented 1 year ago

Ah, looks like it's just the explicit export that's necessary, which adds the overloads as extension functions:

cocoapods {
    framework {
        export("co.touchlab:kermit-simple:2.0.0-RC5")
    }
}

It can still be an api dependency in commonMain. 👍

jeffdgr8 commented 1 year ago

This is working exporting kermit-simple.