Şöyle yaparız. Burada farklı log seviyeleri farklı dosyalara gönderiliyor. ch.qos.logback.classic.filter.ThresholdFilter ve ch.qos.logback.classic.filter.LevelFilter kullanılıyor.
<?xml version="1.0" encoding="UTF-8"?><configuration status="WARN"><property name="logging.error.file.name" value="error-log" /><property name="logging.error.file.path" value="./"/><property name="logging.file.name" value="info-log" /><property name="logging.file.path" value="./"/><!-- Normal log appender --><appender name="INFO_FILE" class="ch.qos.logback.core.FileAppender"><file>${logging.file.path}/${logging.file.name}</file><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern></encoder><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO, DEBUG, TRACE</level></filter><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>ERROR, WARN</level><onMatch>DENY</onMatch><onMisMatch>NEUTRAL</onMisMatch></filter></appender><!-- Error log appender --><appender name="ERROR_FILE" class="ch.qos.logback.core.FileAppender"><file>${logging.error.file.path}/${logging.error.file.name}</file><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern></encoder><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>ERROR, WARN</level></filter><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>INFO, DEBUG, WARN</level><onMatch>DENY</onMatch><onMisMatch>NEUTRAL</onMisMatch></filter></appender><root level="INFO"><appender-ref ref="INFO_FILE"/><appender-ref ref="ERROR_FILE"/></root></configuration>
Açıklaması şöyle
- Trace < Debug < Info < Warn < Error < Fatal- LevelFilter filters events based on exact level matching. If the event's level is equal to the configured level, the filter accepts or denies the event, depending on the configuration of the onMatch and onMismatch properties.- The ThresholdFilter filters events below the specified threshold.
1. Normal appender ThresholdFilter ile INFO, DEBUG, TRACE olaylarının altındakileri kabul etmez.
2. Error appender ThresholdFilter ile ERROR, WARN olaylarının altındakileri kabul etmez.