如何使用 logback.xml 将我的 Apache camel 日志级别设置为错误

How to set my Apache camel log level to ERROR Using logback.xml

我正在对 Apache camel 进行性能测试,到目前为止我能够 运行 logback async 获得一些速度,

有没有在开始我的路线时甚至禁用 camel-context 的 INFO

logback.xml:

而我的 logback.xml 配置是,

<?xml version="1.0" encoding="UTF-8"?>

<configuration debug="false" scan="false">
    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />

    <!-- To show the log in console -->
    <appender name="OUT" class="ch.qos.logback.core.ConsoleAppender">
        <prudent>true</prudent>
        <encoder>
            <Pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
        </encoder>
    </appender>

    <logger name="org.apache.catalina.core" level="INFO" />

    <!-- DEBUG Config -->
    <logger name="logs_debug" level="DEBUG" additivity="false">
        <appender-ref ref="OUT" />
    </logger>

    <!-- INFO Config -->
    <logger name="logs_info" level="INFO" additivity="false">
        <appender-ref ref="OUT" />
    </logger>

    <!-- ERROR Config -->
    <logger name="logs_error" level="ERROR" additivity="false">
        <appender-ref ref="OUT" />
    </logger>

    <!-- To make the Logback ASYNC -->
    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <includeCallerData>true</includeCallerData>
        <queueSize>500</queueSize>
        <discardingThreshold>2</discardingThreshold>
        <appender-ref ref="OUT" />
    </appender>

    <!-- root Logback -->
    <root level="ERROR">
        <appender-ref ref="ASYNC" />
    </root>
</configuration>

我收到了这个回复。

[INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building roi-asynlogback 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ roi-customlogback ---
    [INFO] Deleting /home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ roi-customlogback ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ roi-customlogback ---
    [INFO] Compiling 7 source files to /home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ roi-customlogback ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ roi-customlogback ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ roi-customlogback ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ roi-customlogback ---
    [INFO] Building jar: /home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/target/roi-customlogback-0.0.1-SNAPSHOT.jar
    [INFO] 
    [INFO] >>> camel-maven-plugin:2.13.2:run (default-cli) @ roi-customlogback >>>
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ roi-customlogback ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ roi-customlogback ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ roi-customlogback ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ roi-customlogback ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] <<< camel-maven-plugin:2.13.2:run (default-cli) @ roi-customlogback <<<
    [INFO] 
    [INFO] --- camel-maven-plugin:2.13.2:run (default-cli) @ roi-customlogback ---
    [INFO] Using org.apache.camel.spring.Main to initiate a CamelContext
    [INFO] Starting Camel ...
    Jun 01, 2016 5:26:05 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@47262043: startup date [Wed Jun 01 17:26:05 IST 2016]; root of context hierarchy
    Jun 01, 2016 5:26:05 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from file [/home/bizruntime/BizRuntime/Maven/log4j/roi-customlogback/target/classes/META-INF/spring/camel-context.xml]
    Jun 01, 2016 5:26:06 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5918a58d: defining beans [logFormatter,log,addempdetails,customlogback,template,consumerTemplate,camel-1:beanPostProcessor,camel-1]; root of factory hierarchy
    Jun 01, 2016 5:26:07 PM org.restlet.engine.connector.ServerConnectionHelper start
    INFO: Starting the internal [HTTP/1.1] server on port 9090

尝试查看 link from camels 站点。

日志给出了一些选项: 要使用的日志记录级别。可能的值:ERROR、WARN、INFO、DEBUG、TRACE、OFF

可以这样使用:

.log(LoggingLevel.ERROR, "some error to log")

我的 log4j 具有以下配置并且对我来说运行良好

<logger name="org.apache.camel" additivity="false">
        <level value="ERROR" />
        <appender-ref ref="MYAPPENDER1" />
</logger>
<root level="ERROR"> <appender-ref ref="CONSOLE" /> </root>

我认为 logback 也会是这样的。

不,我不这么认为,因为您正在使用 camel-maven-plugin 启动 Camel,这是一个 Maven 插件,它有自己的启动类型和在 Camel 启动之前发生的日志记录等。

如果你根本不想记录日志,那么自己将 Camel 作为 java 主应用程序启动。

现在的重点是你真的不应该在这上面浪费时间,因为启动是微不足道的,不应该在你的性能测试中进行测量。它仅在应用程序启动时 运行 您可能需要 tweak/tune logging/JMX/threads 以及诸如此类的东西以获得更高的性能。