No log4j2 configuration file found.

今天写的项目报异常:

No log4j2 configuration file found. Using default configuration: logging only errors to the console

解决办法是:

方法一、添加log4j2.xml在src目录下(maven项目在src/main/resources),内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
 
<!-- Author:  Crunchify.com  -->
	<Appenders>
		<Console name="Console" target="SYSTEM_OUT">
			<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
		</Console>
 
		<RollingFile name="RollingFile" filename="log/CrunchifyTest.log"
			filepattern="${logPath}/%d{YYYYMMddHHmmss}-fargo.log">
			<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="100 MB" />
			</Policies>
			<DefaultRolloverStrategy max="20" />
		</RollingFile>
 
	</Appenders>
	<Loggers>
		<Root level="info">
			<AppenderRef ref="Console" />
			<AppenderRef ref="RollingFile" />
		</Root>
	</Loggers>
</Configuration>

方法二、直接在Run configuration-->Arguments-->VM arguments 里添加:

-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF


你可能感兴趣的:(No log4j2 configuration file found.)