Skip to content

Logging for logback on jvm #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Metis-Adrastea opened this issue Apr 5, 2025 · 0 comments
Open

Logging for logback on jvm #310

Metis-Adrastea opened this issue Apr 5, 2025 · 0 comments

Comments

@Metis-Adrastea
Copy link

Hello!
No output to log of io.rsocket on jvm

What is the idiomatic way to organize logging for logback jvm? I looked at current implementations, and did it by analogy with #308

val Slf4jLoggerFactory = object : LoggerFactory {
    private fun LoggingLevel.sl4jLevel() = when (this) {
        LoggingLevel.TRACE -> Level.TRACE
        LoggingLevel.DEBUG -> Level.DEBUG
        LoggingLevel.INFO  -> Level.INFO
        LoggingLevel.WARN  -> Level.WARN
        LoggingLevel.ERROR -> Level.ERROR
    }

    override fun logger(tag: String): Logger = org.slf4j.LoggerFactory.getLogger(tag).let { logger ->
        return object : Logger {
            override val tag: String
                get() = logger.name

            override fun isLoggable(level: LoggingLevel) = logger.isEnabledForLevel(level.sl4jLevel())

            override fun rawLog(
                level: LoggingLevel,
                throwable: Throwable?,
                message: Any?,
            ) {
                logger.atLevel(level.sl4jLevel()).setCause(throwable).log(message?.toString())
            }
        }
    }
}

How correct is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant