spring-boot 开启 log4j 2
spring-boot 开启 log4j 2
yizhichao 发表于1年前
spring-boot 开启 log4j 2
  • 发表于 1年前
  • 阅读 62
  • 收藏 1
  • 点赞 1
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: Log4j 2使用了新一代的基于LMAX Disruptor的无锁异步日志系统。在多线程的程序中,异步日志系统吞吐量比Log4j 1.x和logback高10倍,而时间延迟却更低。

pom.xml

<properties>
	<log4j-core.version>2.6.1</log4j-core.version>
	<java.version>1.8</java.version>
</properties>

<!--web应用基本环境配置 -->
<!-- Add typical dependencies for a web application -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
	<!--排除tomcat,使用jetty服务器 1 -->
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</exclusion>
		<!--使用log4j2替代slf4j 1 -->
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-logging</artifactId>
		</exclusion>
		<exclusion>
			<artifactId>log4j-over-slf4j</artifactId>
			<groupId>org.slf4j</groupId>
		</exclusion>
	</exclusions>
</dependency>

application.properties

# LOGGING
logging.path=d:\allcam\logs
logging.file=uas.log
logging.config=classpath:log4j2.xml

/uas/src/main/resources/log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- status=debug 可以查看log4j的装配过程 -->
<configuration status="off" monitorInterval="1800">
	<properties>
		<property name="LOG_HOME">/log/fish</property>
		<!-- 日志备份目录 -->
		<property name="BACKUP_HOME">{LOG_HOME}/backup</property>
		<property name="STAT_NAME">stat</property>
		<property name="SERVER_NAME">global</property>
	</properties>
	<appenders>
		<!-- 定义控制台输出 -->
		<Console name="Console" target="SYSTEM_OUT" follow="true">
			<PatternLayout
				pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
		</Console>
		<!-- 程序员调试日志 -->
		<RollingRandomAccessFile name="DevLog"
			fileName="${LOG_HOME}/${SERVER_NAME}" filePattern="${LOG_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log">
			<PatternLayout
				pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"
					modulate="true" />
			</Policies>
		</RollingRandomAccessFile>
		<!-- 产品数据分析日志 -->
		<RollingRandomAccessFile name="ProductLog"
			fileName="${LOG_HOME}/${SERVER_NAME}_${STAT_NAME}"
			filePattern="${LOG_HOME}/${SERVER_NAME}_${STAT_NAME}.%d{yyyy-MM-dd-HH}.log">
			<PatternLayout
				pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
			<Policies>
				<TimeBasedTriggeringPolicy interval="1"
					modulate="true" />
			</Policies>
		</RollingRandomAccessFile>
	</appenders>
	<loggers>
		<!-- 3rdparty Loggers -->
		<logger name="org.springframework.core" level="info">
		</logger>
		<logger name="org.springframework.beans" level="info">
		</logger>
		<logger name="org.springframework.context" level="info">
		</logger>
		<logger name="org.springframework.web" level="info">
		</logger>
		<logger name="org.jboss.netty" level="warn">
		</logger>
		<logger name="org.apache.http" level="warn">
		</logger>
		<logger name="com.mchange.v2" level="warn">
		</logger>
		<!-- APP Stat logger -->
		<logger name="com.allcam.uas" level="info"
			additivity="false">
			<appender-ref ref="ProductLog" />
		</logger>
		<!-- Root Logger -->
		<root level="DEBUG">
			<appender-ref ref="DevLog" />
			<appender-ref ref="Console" />
		</root>
	</loggers>
</configuration>

 

共有 人打赏支持
yizhichao
粉丝 11
博文 294
码字总数 266067
×
yizhichao
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: