文件名log4j2.xml:
<?xmlversion="1.0"encoding="UTF-8"?> <configurationstatus="INFO"> <Properties> <Propertyname="LOG_HOME">h://logs//web</Property> </Properties> <appenders> <Consolename="STDOUT"target="SYSTEM_OUT"> <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)--> <ThresholdFilterlevel="DEBUG"onMatch="ACCEPT"onMismatch="DENY"/> <PatternLayoutpattern="%d{HH:mm:ss.SSS}[%t]%-5level-%msg-[%logger{36}:%M:%L]%n"/> </Console> <!--主日志文件--> <RollingFilename="RoFile"fileName="${LOG_HOME}/MainServer.log" filePattern="${LOG_HOME}/$${date:yyyy-MM-dd}/MainServer-%d{yyyy-MM-dd}-%i.log"> <PatternLayoutpattern="%d{yyyy.MM.ddHH:mm:ss.SSS}[%t]%-5level-%msg-[%logger{36}:%M:%L]%n"/> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicysize="250MB"/> </Policies> <!--最大保留10个文件--> <DefaultRolloverStrategymax="10"/> </RollingFile> </appenders> <loggers> <Loggername="org.springframework"level="INFO"additivity="true"> <AppenderRefref="STDOUT"/> </Logger> <Loggername="org.apache.ibatis"level="DEBUG"additivity="true"> <AppenderRefref="STDOUT"/> </Logger> <Loggername="java.sql.Connection"level="DEBUG"additivity="true"> <AppenderRefref="STDOUT"/> </Logger> <Loggername="java.sql.PreparedStatement"level="DEBUG"additivity="true"> <AppenderRefref="STDOUT"/> </Logger> <Loggername="java.sql.ResultSet"level="DEBUG"additivity="true"> <AppenderRefref="STDOUT"/> </Logger> <rootlevel="INFO"> <appender-refref="RoFile"/> <appender-refref="STDOUT"/> </root> </loggers> </configuration>原文链接:https://www.f2er.com/xml/296147.html