touchlab / Kermit

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

Expose formatter to public or protected in CommonWriter #360

Open c0nstexpr opened 1 year ago

c0nstexpr commented 1 year ago

https://github.com/touchlab/Kermit/blob/8e20fa506771c5078b55c0a32ef93e2889aba10e/kermit-core/src/commonMain/kotlin/co/touchlab/kermit/CommonWriter.kt#L19 At now CommonWriter's formatter is private, which make it impossible to use custom formatter when inheriting writer. See below

class MyWriter() : CommonWriter(MyFormatter()) {
    override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) =
        // Cannot access 'messageStringFormatter': it is invisible (private in a supertype)
        Mylog.log(messageStringFormatter.formatMessage(severity, Tag(tag), Message(message)))
}
findjigar commented 1 year ago

It's possible to customize Message Formatting. Did you check out this docs? https://kermit.touchlab.co/docs/configuration/MESSAGE_FORMATTING

c0nstexpr commented 1 year ago

It's possible to customize Message Formatting. Did you check out this docs? https://kermit.touchlab.co/docs/configuration/MESSAGE_FORMATTING

Yes, I know the current way to customize log writer. And I also successfully implement my own writer. But if we implement a class to inherit CommonWriter, providing customization by overriding base log method seems to be pointless. Because the inheritor cannot access the formatter.