Logback.xml configuration -
i trying configure stout save file. however, not saved file - have idea why?. - want log file name configurable inside logback.xml {log_file_name} come cmd - possible?
this logback.xml:
<?xml version="1.0" encoding="utf-8"?> <!-- assistance related logback-translator or configuration --> <!-- files in general, please contact logback user mailing list --> <!-- @ http://www.qos.ch/mailman/listinfo/logback-user --> <!-- --> <!-- professional support please see --> <!-- http://www.qos.ch/shop/products/professionalsupport --> <!-- --> <configuration> <appender name="defaultlog" class="ch.qos.logback.core.rolling.rollingfileappender"> <!--see http://logback.qos.ch/manual/appenders.html#rollingfileappender--> <file>sarit_test.log</file> <encoder> <pattern>%d{dd mmm yyyy hh:mm:ss.sss} [%t] %-5p %x %f:%l - %m</pattern> </encoder> <rollingpolicy class="ch.qos.logback.core.rolling.fixedwindowrollingpolicy"/> <triggeringpolicy class="ch.qos.logback.core.rolling.sizebasedtriggeringpolicy"> <maxfilesize>50000kb</maxfilesize> </triggeringpolicy> </appender> <root level="info"> <appender-ref ref="defaultlog"/> </root> </configuration>
for first answer, check here : https://github.com/abdulwaheed18/slf4jtutorial
second answer : have use sift appender take system parameters file.
<appender name="sift" class="ch.qos.logback.classic.sift.siftingappender"> <!-- in absence of class attribute, assumed desired discriminator type ch.qos.logback.classic.sift.mdcbaseddiscriminator --> <discriminator> <key>file_name</key> <defaultvalue>default_file_name</defaultvalue> </discriminator> <sift> <appender name="file-${file_name}" class="ch.qos.logback.core.rolling.rollingfileappender"> <filter class="ch.qos.logback.core.filter.evaluatorfilter"> <evaluator> <!-- defaults type ch.qos.logback.classic.boolex.janinoeventevaluator --> <expression>return message.contains("broken pipe");</expression> </evaluator> <onmismatch>neutral</onmismatch> <onmatch>deny</onmatch> </filter> <file>${logdir}/${file_name}.log</file> <rollingpolicy class="ch.qos.logback.core.rolling.timebasedrollingpolicy"> <filenamepattern>${logdir}/${file_name}.%d{yyyy-mm-dd}.%i.log.gz </filenamepattern> <!-- keep 30 days' worth of history --> <maxhistory>30</maxhistory> <!-- limit logs size 300mb --> <timebasedfilenamingandtriggeringpolicy class="ch.qos.logback.core.rolling.sizeandtimebasedfnatp"> <!-- or whenever file size reaches 10mb --> <maxfilesize>10mb</maxfilesize> </timebasedfilenamingandtriggeringpolicy> </rollingpolicy> <encoder class="ch.qos.logback.classic.encoder.patternlayoutencoder"> <pattern>%date [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> </sift> </appender>
Comments
Post a Comment