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

Ubuntu 16.04+Java8环境下如何仅开启AWS KCL/KPL的ERROR与WARN日志?

How to Restrict AWS KCL/KPL Logs to ERROR/WARN Level (Ubuntu 16.04 + Java 8)

Got it, let's sort out this log noise issue for AWS KCL and KPL on your Ubuntu 16.04 + Java 8 setup. Since you don't have an existing log configuration file, we'll build one from scratch based on the logging frameworks these libraries typically use (most often SLF4J with Logback, or Log4j 2).

Option 1: Using Logback (Most Common Default)

AWS KCL/KPL often rely on SLF4J with Logback as the underlying logger. Here's how to create a config file to filter out INFO logs:

  1. Create the Logback config file
    In your project's src/main/resources directory (or place it in your Java classpath if running a standalone JAR), make a file named logback.xml with this content:

    <configuration>
        <!-- Console output (since you don't use log files) -->
        <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>
    
        <!-- Set root log level to WARN (includes ERROR and WARN only) -->
        <root level="WARN">
            <appender-ref ref="CONSOLE"/>
        </root>
    
        <!-- Explicitly lock AWS KCL/KPL packages to WARN level -->
        <!-- Covers older KCL versions -->
        <logger name="com.amazonaws.services.kinesis" level="WARN" additivity="false">
            <appender-ref ref="CONSOLE"/>
        </logger>
        <!-- Covers newer KCL versions (software.amazon namespace) -->
        <logger name="software.amazon.kinesis" level="WARN" additivity="false">
            <appender-ref ref="CONSOLE"/>
        </logger>
        <!-- KPL package -->
        <logger name="com.amazonaws.services.kinesis.producer" level="WARN" additivity="false">
            <appender-ref ref="CONSOLE"/>
        </logger>
    </configuration>
    
    • The additivity="false" flag prevents duplicate log entries (since the root logger already handles console output).
    • We target both old and new AWS package namespaces to cover all KCL versions.
  2. Ensure the config is in your classpath

    • If using a build tool like Maven/Gradle, placing the file in src/main/resources will automatically include it in your JAR.
    • For standalone JARs, put the logback.xml in the same directory as your JAR and run with:
      java -cp ".:your-application.jar" com.your.package.MainClass
      

Option 2: Using Log4j 2

If your project uses Log4j 2 instead, create a log4j2.xml file in src/main/resources (or your classpath) with this content:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <!-- Root log level set to WARN -->
        <Root level="WARN">
            <AppenderRef ref="Console"/>
        </Root>

        <!-- AWS KCL/KPL specific loggers -->
        <Logger name="com.amazonaws.services.kinesis" level="WARN" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
        <Logger name="software.amazon.kinesis" level="WARN" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
        <Logger name="com.amazonaws.services.kinesis.producer" level="WARN" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
    </Loggers>
</Configuration>

Follow the same classpath steps as above to ensure the config is picked up.

Verify the Setup

After applying the config, start your application. You should only see ERROR and WARN level logs from AWS KCL/KPL, with all the noisy INFO entries suppressed.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:54:51