【Java】系统找不到指定路径
报错信息:
2021-05-26 13:50:11,737 RMI TCP Connection(3)-127.0.0.1 ERROR DefaultRolloverStrategy contains an invalid element or attribute "maxDepth" 2021-05-26 13:50:11,745 RMI TCP Connection(3)-127.0.0.1 ERROR Unable to create file e:/log/dmscc/repair/repair.log java.io.IOException: 系统找不到指定的路径。 at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(File.java:1012) at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:525)
线索是log相关,找到了Log4J的XML配置文件:
配置描述:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %5p [%C{1}:%L] - %m%n" /> </Console> <RollingFile name="RollingFile" fileName="${LOG_HOME.DIR}/repair/repair.log" filePattern="${LOG_HOME.DIR}/repair/repair-%d{yyyy-MM-dd}-%i.log.gz"> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %5p [%C{1}:%L] - %m%n" /> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true" /> <SizeBasedTriggeringPolicy size="50 MB" /> <CronTriggeringPolicy schedule="0 0 0 * * ?"/> </Policies> <DefaultRolloverStrategy maxDepth="100" max="200"> <Delete basePath="${LOG_HOME.DIR}/repair" maxDepth="2"> <IfFileName glob="repair-*.log.gz" /> <IfLastModified age="45d" /> </Delete> </DefaultRolloverStrategy> </RollingFile> </Appenders> <Loggers> <Logger name="com.yonyou.dms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Logger name="com.yonyou.gms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Logger name="com.yonyou.dmsgms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Root level="info"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Root> </Loggers> </Configuration>
和报错信息对比发现是这一段配置描述:
<RollingFile name="RollingFile" fileName="${LOG_HOME.DIR}/repair/repair.log"
原因:
这个项目的路径是默认找到E盘下面去输出的,但是我没有E盘啊
解决方案也就两种:
一、我从已有的盘中开个新分区划分给E盘,这样日志能找到盘符输出了
二、我不想分盘,直接更改日志的输出路径,但是这个是动态指定的,于是我就写死指定到某一个位置
所以还是改了日志配置:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %5p [%C{1}:%L] - %m%n" /> </Console> <!-- <RollingFile name="RollingFile" fileName="${LOG_HOME.DIR}/repair/repair.log"--> <!--filePattern="${LOG_HOME.DIR}/repair/repair-%d{yyyy-MM-dd}-%i.log.gz">--> <RollingFile name="RollingFile" fileName="d:/log/dmscc/repair/repair.log" filePattern="d:/log/dmscc/repair/repair-%d{yyyy-MM-dd}-%i.log.gz"> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %5p [%C{1}:%L] - %m%n" /> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true" /> <SizeBasedTriggeringPolicy size="50 MB" /> <CronTriggeringPolicy schedule="0 0 0 * * ?"/> </Policies> <DefaultRolloverStrategy maxDepth="100" max="200"> <!--<Delete basePath="${LOG_HOME.DIR}/repair" maxDepth="2">--> <Delete basePath="d:/log/dmscc/repair" maxDepth="2"> <IfFileName glob="repair-*.log.gz" /> <IfLastModified age="45d" /> </Delete> </DefaultRolloverStrategy> </RollingFile> </Appenders> <Loggers> <Logger name="com.yonyou.dms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Logger name="com.yonyou.gms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Logger name="com.yonyou.dmsgms" level="debug" additivity="false"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Logger> <Root level="info"> <!--<AppenderRef ref="Console" />--> <AppenderRef ref="RollingFile" /> </Root> </Loggers> </Configuration>
他写了三个,我上面只更改了第一个路径再跑项目就能起来
其他两个的左右没有搞懂是干嘛的,干脆也跟着改掉了