如何更改Kaa客户端的日志级别

时间:2017-02-08 16:34:00

标签: java slf4j kaa

我一直在关注Kaa提供的教程(谢谢!)和文档。我在java中开发了一个完美运行的kaa-client,它已经部署完毕。 但是,它确实非常冗长。它适用于调试和东西,但现在它正在创建一个巨大的日志。有没有办法避免特定类和包的INFO消息 - 比如“ org.kaaproject.kaa.client.channel.impl。*

1 个答案:

答案 0 :(得分:0)

要为kaa日志配置特定级别,您应配置相应的日志架构文件。默认情况下,它是 logback.xml 。 例如,对于数据收集演示的Java源,日志架构为: JDataCollectionDemo / res / logback.xml 要避免特定类或包的INFO消息,只需将具有ERROR级别的相应行添加到模式中,例如:

<logger name="org.kaaproject.kaa.client.channel.impl" level="ERROR"/>

在这种情况下,完整的日志架构将是:

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

         Copyright 2014-2016 CyberVision, Inc.

         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at

              http://www.apache.org/licenses/LICENSE-2.0

         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.

    -->

    <configuration>
        <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>

        <appender name="fileLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>kaa-desktop-client.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
                <maxHistory>30</maxHistory>
            </rollingPolicy>
            <encoder>
                <pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>

        <root level="INFO">
            <appender-ref ref="console"/>
            <appender-ref ref="fileLogAppender"/>
        </root>

        <logger name="org.kaaproject.kaa" level="ERROR"/>
        <logger name="org.kaaproject.kaa.client.logging.memory" level="INFO"/>
        <logger name="org.kaaproject.kaa.demo.datacollection" level="INFO"/>
        <logger name="org.kaaproject.kaa.client.channel.impl" level="ERROR"/>
    </configuration>

还可以更改Sandbox中日志的日志级别: 对于 /var/log/kaa/kaa-node.log /var/log/kaa/kaa-sandbox.log ,相应的日志架构文件为: /usr/lib/kaa-node/conf/logback.xml /usr/lib/kaa-sandbox/conf/logback.xml 在沙箱日志架构配置后,应重新启动相应的服务:

sudo service kaa-node restart
sudo service kaa-sandbox restart