我为我的应用程序编写了logback配置文件,但是当我在进行maven clean install(mvn clean install)时,它在项目目录中生成了一个带有日志文件的catalina.home_IS_UNDEFINED目录.
为什么生成这个目录?
为什么生成这个目录?
我不希望它出现在我的项目目录中.
有什么帮助解决这个问题?
这是配置文件.
<?xml version="1.0" encoding="UTF-8" ?> <configuration> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{HH:mm:ss.SSS} %-5p [%t] %c{1} - %m%n</pattern> </encoder> </appender> <appender name="MY_APP_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${catalina.home}/logs/myApplication.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${catalina.home}/logs/myApplication.%d{yyyy-MM-dd}.log</FileNamePattern> </rollingPolicy> <encoder> <pattern>%-5p %date{HH:mm:ss.SSS} [%t] %c{1} - %m%n</pattern> </encoder> <append>true</append> </appender> <logger name="org.springframework" level="WARN"/> <root> <priority value="INFO"/> <appender-ref ref="CONSOLE"/> <appender-ref ref="MY_APP_LOG"/> </root> </configuration>
解决方法
背景
此属性加载失败,因为它仅由tomcat填充.它不是由maven编译任务填充的.
解决方案1
在logback.xml中设置这样的属性
<?xml version="1.0" encoding="UTF-8"?> <configuration> <if condition='isDefined("catalina.home")'> <then> <property name="log.folder" value="${catalina.home}/logs"/> </then> <else> <property name="log.folder" value="./target/logs"/> </else> </if> <appender name="companyMyAppServiceAppender" class="ch.qos.logback.core.FileAppender"> <file>${log.folder}/company.myApp.log</file> ... </appender> ... </configuration>
解决方案2
“重写”值:
<property name="log.folder" value="./target/logs"/> <if condition='isDefined("catalina.home")'> <then> <property name="log.folder" value="${catalina.home}/logs"/> </then> </if>
NB!
并且不要忘记导入maven janino依赖
<!-- The org.codehaus.janino:commons-compiler:2.7.8 dependency --> <!-- will be automatically pulled in by Maven's transitivity rules --> <dependency> <groupId>org.codehaus.janino</groupId> <artifactId>janino</artifactId> <version>2.7.8</version> </dependency>