I am using standard logback in Spring-Boot for logging.
I want every logger in a different file. Today I need to do this way.
logback-spring.xml
<configuration>
<appender name="FILE_LOG1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/logger1.log</file>
...
</appender>
<appender name="FILE_LOG2" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/logger2.log</file>
...
</appender>
<logger name="logger1" level="DEBUG">
<appender-ref ref="FILE_LOG1" />
</logger>
<logger name="logger2" level="DEBUG">
<appender-ref ref="FILE_LOG2" />
</logger>
...
Thats not very handy. If my appenders are pretty long and I have a lot of loggers it is pretty a long config.
Is there a way I can place the name of the logger into the logfile-name in the appender?
So I would only need 1 appender.
You can try to use the
SiftingAppenderinLogbackwhich can separate logs based on runtime attributes.SiftingAppenderuses a discriminator to determine the log file name at runtime. The${loggerName}placeholder in the file attribute of theRollingFileAppenderis replaced with the name of the logger for each log message.!!!But take into account that
SiftingAppendermore resource-intensive than a regular appender.