Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set log level for a specific class in spring with logback.xml?

I am trying to not log debug message in class com.data.march.ClientUtils. For that, I think that I can change the log level of that class in the logback.xml to error.

Here is my logback.xml:

<configuration>

    <appender name="dailyRollingFileAppender"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>c:/Logs/logato.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <FileNamePattern>c:/Logato/Data/Logs/Logato.%d{yyyy-MM-dd}.log</FileNamePattern>
            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <Pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{35} - %msg %n
            </Pattern>
        </encoder>
    </appender>

    <appender name="minuteRollingFileAppender"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover every minute -->
            <FileNamePattern>c:/Data/Logs/minutes/Logato-minute.%d{yyyy-MM-dd_HH-mm}.log
            </FileNamePattern>
            <!-- keep 30 minutes' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <Pattern>%-4relative %-5level [%thread] %logger{35} - %msg %n
            </Pattern>
        </encoder>
    </appender>

    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
            </Pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>TRACE</level>
        </filter>
    </appender>

    <logger name="org" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="dailyRollingFileAppender"/>
        <appender-ref ref="consoleAppender"/>
    </logger>
    <logger name="com.data" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="dailyRollingFileAppender"/>
        <appender-ref ref="consoleAppender"/>
    </logger>
    <logger name="org" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="dailyRollingFileAppender"/>
    </logger>
    <logger name="com.data.march.ClientUtils" additivity="false">
        <level value="ERROR"/>
    </logger>
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </root>
</configuration>

But my attempt failed. Do you have any idea?

like image 857
TinyOS Avatar asked Apr 20 '17 16:04

TinyOS


People also ask

How do you change the logging level in spring?

If you are on Spring Boot then you can directly add following properties in application. properties file to set logging level, customize logging pattern and to store logs in the external file. These are different logging levels and its order from minimum << maximum.

How do you specify Logback xml in application properties?

xml , you can use <springProperty> to access properties from Spring's environment including those configured in application. properties . This is described in the documentation: The tag allows you to surface properties from the Spring Environment for use within Logback.


1 Answers

Try with adding this:

<logger name="com.data.march.ClientUtils" level="error"/>
like image 101
Monzurul Shimul Avatar answered Oct 12 '22 12:10

Monzurul Shimul