java - Is there a way in logback.xml to specify file log destination through classpath:, without absolute path? -
i've in logback.xml configuration file appender:
<appender name="file" class="ch.qos.logback.core.rolling.rollingfileappender"> <file>classpath:addressbooklog.log</file> <encoder class="ch.qos.logback.classic.encoder.patternlayoutencoder"> <pattern>%d{dd mmm yyyy;hh:mm:ss} %-5level %logger{36} - %msg%n </pattern> </encoder> <rollingpolicy class="ch.qos.logback.core.rolling.fixedwindowrollingpolicy"> <filenamepattern>classpath:addressbooklog.%i.log.zip</filenamepattern> <minindex>1</minindex> <maxindex>10</maxindex> </rollingpolicy> <triggeringpolicy class="ch.qos.logback.core.rolling.sizebasedtriggeringpolicy"> <maxfilesize>2mb</maxfilesize> </triggeringpolicy> </appender> so specify path file in print logs in relative way through classpath, doesn't work, no file addressbooklog.log created , written. works absolute paths /home/andrea/.../resources/addressbooklog.log have ideas on how make work classpath?
the chapter 3: logback configuration: variable substitution told various ways refer variable defined outside, e.g. system properties , classpath.
the significant configuration creating separate file contain variables. can make reference resource on class path instead of file well. e.g.
the logback.xml
<configuration> <property resource="resource1.properties" /> <appender name="file" class="ch.qos.logback.core.fileappender"> <!-- here can refer variable defined @ resource1.properties --> <file>${user_home}/myapp.log</file> <encoder> <pattern>%msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="file" /> </root> </configuration> the external properties file (resource1.properties)
user_home=/path/to/somewhere please note resource1.properties resource available @ classpath.
you may refer full version @ chapter 3: logback configuration: variable substitution. hope may help.
Comments
Post a Comment