温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

spring boot log

发布时间:2020-06-19 20:37:12 来源:网络 阅读:2027 作者:xiaosawuhen 栏目:开发技术

demo:

    https://github.com/xiaosawuhen/spring-boot-log

spring boot log存在两种形式

1.使用默认的logback

    直接在application.properties中设置

        ## spring boot log4j
	logging.level.org.springframework.web=INFO
	logging.level.guru.springframework.blogs.controllers=INFO
	logging.level.org.hibernate=ERROR
	logging.file=logs/spring-boot-logging.log


2.使用log4j


pom.xml

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
	</parent>

	<properties>
    	<java.version>1.8</java.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
                <exclusion>  
                    <groupId>org.springframework.boot</groupId>  
                    <artifactId>spring-boot-starter-logging</artifactId>  
                </exclusion>  
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-log4j2</artifactId>
		</dependency>
	</dependencies>


application.properties

	logging.config=classpath:log4j2.xml



log4j2.xml

	<?xml version="1.0" encoding="UTF-8" ?>
	<configuration status="WARN">
		<!--全局参数-->
		<Properties>
			<Property name="pattern">%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n</Property>
		</Properties>
		<Loggers>
			<Root level="DEBUG">
				<AppenderRef ref="console"></AppenderRef>
				<AppenderRef ref="rolling_file"></AppenderRef>
				<AppenderRef ref="file"></AppenderRef>
			</Root>
		</Loggers>
		<Appenders>
			<Console name="console" target="SYSTEM_OUT" follow="true">
				<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
				<PatternLayout>
					<Pattern>${pattern}</Pattern>
				</PatternLayout>
			</Console>
			<RollingFile name="rolling_file"
						 fileName="logs/info.log"
						 filePattern="${log4j2.root.path}_%d{yyyy-MM-dd}.log">
				<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
				<PatternLayout>
					<Pattern>${pattern}</Pattern>
				</PatternLayout>
				<Policies>
					<!-- <TimeBasedTriggeringPolicy interval="1"/> -->
					<SizeBasedTriggeringPolicy size="1000 KB"/>
				</Policies>
			</RollingFile>
			<File name="file" fileName="logs/current.log">
				<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
				<PatternLayout>
					<Pattern>${pattern}</Pattern>
				</PatternLayout>
			</File>
		</Appenders>
	</configuration>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI