You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Exposed Framework日志?基于Kotlin Gradle的桌面应用

How to Disable Exposed ORM Logs and Keep Only kotlin-logging Output in a Gradle/Kotlin Desktop App

Absolutely! While Exposed doesn’t offer a dedicated Gradle property to toggle its logs directly, you can use Gradle to manage your logging framework configuration—effectively silencing Exposed’s verbose output while preserving your custom io.github.microutils:kotlin-logging logs. Here’s a step-by-step solution:

1. Ensure You’re Using a Configurable Logging Implementation

Exposed relies on SLF4J for logging, so you’ll need a concrete implementation like Logback (the most common choice with kotlin-logging). Add these dependencies to your build.gradle.kts if you haven’t already:

dependencies {
    // kotlin-logging core
    implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")
    // Logback as SLF4J's runtime implementation
    runtimeOnly("ch.qos.logback:logback-classic:1.4.8")
}

2. Define Logging Levels via Gradle Properties

Add these properties to your gradle.properties file to centralize control over log levels:

# Set the log level for your app's custom logs (adjust to DEBUG/INFO as needed)
appLogLevel=INFO
# Disable Exposed and SQLite driver logs (use OFF to silence entirely, ERROR for only critical issues)
exposedLogLevel=OFF

3. Pass Gradle Properties to the JVM

In your build.gradle.kts, configure the JavaExec task to pass these properties as system properties, so your logging framework can read them:

tasks.withType<JavaExec> {
    systemProperty("app.log.level", property("appLogLevel"))
    systemProperty("exposed.log.level", property("exposedLogLevel"))
}

4. Configure Logback to Filter Logs

Create a logback.xml file in src/main/resources and use the system properties to filter logs:

<configuration>
    <!-- Console appender for your custom logs -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Route your app's logs to the console (replace com.your.app with your actual package) -->
    <logger name="com.your.app" level="${app.log.level}" additivity="false">
        <appender-ref ref="CONSOLE" />
    </logger>

    <!-- Silence Exposed's core logs -->
    <logger name="org.jetbrains.exposed" level="${exposed.log.level}" additivity="false" />
    <!-- Optional: Silence SQLite driver logs if they're also cluttering your console -->
    <logger name="org.sqlite" level="${exposed.log.level}" additivity="false" />

    <!-- Turn off root logs to prevent other framework noise -->
    <root level="OFF" />
</configuration>

Quick Alternative (No Logback Config)

If you want a simpler, temporary fix without a log config file, you can directly set SLF4J system properties in Gradle (works with SLF4J’s SimpleLogger implementation):

tasks.withType<JavaExec> {
    // Disable Exposed logs entirely
    systemProperty("org.slf4j.simpleLogger.log.org.jetbrains.exposed", "off")
    // Keep your app's logs at INFO level (replace com.your.app with your package)
    systemProperty("org.slf4j.simpleLogger.log.com.your.app", "info")
    // Disable root logger
    systemProperty("org.slf4j.simpleLogger.defaultLogLevel", "off")
}

This approach ensures only your kotlin-logging statements appear in the console, while Exposed’s internal logs are suppressed entirely.

内容的提问来源于stack exchange,提问作者kerosinkin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:54:42