码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot log

时间:2018-01-24 16:59:45      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:ram   ase   size   ogg   .so   pid   .config   stat   2.x   

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>


spring boot log

标签:ram   ase   size   ogg   .so   pid   .config   stat   2.x   

原文地址:http://blog.51cto.com/xinzhilian/2064648

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!