java - logback loading all appenders -
i have logback.xml file 3 appender in : 1 consoleappender , 2 fileappender
<?xml version="1.0" encoding="utf-8"?> <configuration> <appender name="stdout" class="ch.qos.logback.core.consoleappender"> <target>system.out</target> <encoder> <pattern>[%d{yyyy-mm-dd hh:mm:ss}] %msg%m%n%ex</pattern> </encoder> </appender> <appender name="bappender" class="ch.qos.logback.core.fileappender"> <file>logs/b.txt</file> <append>true</append> <encoder> <pattern>[%d{yyyy-mm-dd hh:mm:ss}] -[%t] %-4r %-5p %c : %n%m%n</pattern> </encoder> </appender> <appender name="aappender" class="ch.qos.logback.core.fileappender"> <file>logs/a.txt</file> <append>false</append> <encoder> <pattern>[%d{dd/mm/yyyy : hh:mm:ss} %level - %logger] %m%n</pattern> </encoder> </appender> <logger name="alogger" additivity="false"> <level value="debug" /> <appender-ref ref="aappender" /> </logger> <root level="info"> <appender-ref ref="stdout"/> </root> </configuration>
the problem when launch programme associated alogger(logger logger = loggerfactory.getlogger("alogger");
. add together bappend ( , create empty b.txt file ....)
it's logback phone call , execute appender when logger called regardless attached appender. how avoid behaviour ?
thank much
in short, think reply 'no', there isn't way prevent b.txt
beingness created. looking @ source fileappender
, appears output file (and corresponding parent folder hierarchy) created when appender started (which happens when logback initialized). design deliberate, since approach save considerable time during logging.
java logback fileappender
No comments:
Post a Comment