SpringBoot(八)----SpringBoot配置日志文件

今天介绍一下SpringBoot配置日志文件

SpringBoot在所有的内部日志中使用Commons Logging,但是默认配置也提供了对常用日志的支持,如Java Util Logging,Log4J,Log4J2和Logback。但是每种Logger都可以通过配置使用控制台或者文件输出日志内容。

一.SpringBoot默认日志Logback

SLF4J,是一个针对各类Java日志框架的统一Façade抽象。Java有很多的日志框架,如java.util.logging,log4j,logback,commons-logging,Spring框架使用的是Jakarta Commons Logging API(JCL)。而SLF4J定义了统一的日志抽象接口,而真正的日志实现则是在运行决定的。

Logback是log4j框架的作者开发的新一代日志框架,它能够适应诸多运行环境,支持SLF4J。

默认情况下,SpringBoot使用SLF4J+Logback记录日志。

二.日志输出的内容元素

日志输出的内容元素具体如下:

时间日期:精确到毫秒

日志级别:ERROR,WARN,INFO,DEBUG,TRACE

进程ID

分隔符:---标识实际日志的开始

线程名:方括号括起来的内容

Logger名:通常为源代码类名

日志内容

三.添加日志依赖

网上给出的日志依赖为:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
</dependency>

Spring boot应用将自动使用logback作为应用日志框架,Spring Boot启动的时候,由org.springframework.boot.logging.Logging-Application-Listener根据情况初始化并使用。spring-boot-starter中包含spring-boot-starter-logging,该依赖内容就是Spring boot默认的日志框架logback。

我自己使用的依赖如下:

<dependency>      <groupId>org.slf4j</groupId>      <artifactId>slf4j-api</artifactId>      <version>1.7.20</version>
</dependency>
<!-- 添加logback-classic依赖 -->
<dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
</dependency>
<!-- 添加logback-core依赖 -->
<dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
</dependency>

四.控制台输出

日志级别从低到高分别是TRACE<DEBUG<INFO<WARN<ERROR<FATAL,如果设置为WARN,则低于WARN的信息都不会被输出。

SpringBoot中默认配置ERROR、WARN和INFO级别的日志输出到控制台。

在application.properties中配置logging.level.包名=‘日志级别’,可以控制控制台输出日志级别,举个例子:

首先,建一个springboot项目,项目目录如下:

第二步,配置pom.xml文件,加入jar包

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>springboot_002</groupId>
	<artifactId>springboot_002</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>springboot_002 Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.20</version>
		</dependency>
		<!-- 添加logback-classic依赖 -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
		</dependency>
		<!-- 添加logback-core依赖 -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>
		<!-- 继承父包 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.3.RELEASE</version>
	</parent>
	<build>
		<finalName>springboot_002</finalName>
	</build>
</project>

第三步,在src/main/java目录下建包com.zk.myspringboot,并创建一个SpringBootApplicationFirst.java启动类。

SpringBootApplicationFirst.java

package com.zk.myspringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootApplicationFirst extends SpringBootServletInitializer{
	public static void main(String[]args){
        SpringApplication.run(SpringBootApplicationFirst.class, args);
    }
}

第四步,在src/main/resources目录下配置application.properties文件,在application.properties中配置日志等级,如下:

logging.level.com.zk=debug

这里的日志级别等级可以更改。

最后,我们在src/test/java下创建包com.zk.myspringboot(测试类包名需要与启动类包名保持一致),并在包中创建一个测试类SpringBootApplicationTest.java。

SpringBootApplicationTest.java

package com.zk.myspringboot;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootApplicationTests {
	//日志的级别
	/*
	 * 日志的级别是由高到低的
	 * SpringBoot默认日志级别---info级别
	 * trace>debug>info>warn>error
	 */
	//记录器
	Logger logger=LoggerFactory.getLogger(getClass());
	@Test
	public void contextLoads() {
		logger.trace("这是trace日志...");
		logger.debug("这是debug日志...");
		logger.info("这是info日志...");
		logger.warn("这是warn日志...");
		logger.error("这是error日志...");
	}
}

我们启动测试类,执行结果如下: 

可以看到日志的输出内容。

当然我们可以通过配置属性文件中的logging.file或者logging.path将日志文件输出到单独的文件中,需要注意的的是,这两个配置文件的属性值不可同时使用,否则

只有logging.file生效。

一.如果我们配置

logging.file=SpringBoot.log

则在工程目录下会生成一个SpringBoot.log文件。

日志文件内容如下:

2020-04-08 16:38:31.006  INFO 20008 --- [main] c.z.m.SpringBootApplicationTests         : Starting SpringBootApplicationTests on zhangkun0400 with PID 20008 (started by zhangkun04 in D:\eclipseworkspace\springboot_002)
2020-04-08 16:38:31.006 DEBUG 20008 --- [main] c.z.m.SpringBootApplicationTests         : Running with Spring Boot v1.4.3.RELEASE, Spring v4.3.5.RELEASE
2020-04-08 16:38:31.007  INFO 20008 --- [main] c.z.m.SpringBootApplicationTests         : No active profile set, falling back to default profiles: default
2020-04-08 16:38:31.036  INFO 20008 --- [main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:38:31 CST 2020]; root of context hierarchy
2020-04-08 16:38:32.802  INFO 20008 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:38:31 CST 2020]; root of context hierarchy
2020-04-08 16:38:32.842  INFO 20008 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-04-08 16:38:32.844  INFO 20008 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-04-08 16:38:32.870  INFO 20008 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:38:32.870  INFO 20008 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:38:32.901  INFO 20008 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:38:33.050  INFO 20008 --- [main] c.z.m.SpringBootApplicationTests         : Started SpringBootApplicationTests in 2.379 seconds (JVM running for 3.06)
2020-04-08 16:38:33.073 DEBUG 20008 --- [main] c.z.m.SpringBootApplicationTests         : 这是debug日志...
2020-04-08 16:38:33.073  INFO 20008 --- [main] c.z.m.SpringBootApplicationTests         : 这是info日志...
2020-04-08 16:38:33.074  WARN 20008 --- [main] c.z.m.SpringBootApplicationTests         : 这是warn日志...
2020-04-08 16:38:33.074 ERROR 20008 --- [main] c.z.m.SpringBootApplicationTests         : 这是error日志...
2020-04-08 16:38:33.080  INFO 20008 --- [Thread-1] o.s.w.c.s.GenericWebApplicationContext   : Closing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:38:31 CST 2020]; root of context hierarchy
2020-04-08 16:46:06.593  INFO 14984 --- [main] c.z.m.SpringBootApplicationTests         : Starting SpringBootApplicationTests on zhangkun0400 with PID 14984 (started by zhangkun04 in D:\eclipseworkspace\springboot_002)
2020-04-08 16:46:06.594 DEBUG 14984 --- [main] c.z.m.SpringBootApplicationTests         : Running with Spring Boot v1.4.3.RELEASE, Spring v4.3.5.RELEASE
2020-04-08 16:46:06.594  INFO 14984 --- [main] c.z.m.SpringBootApplicationTests         : No active profile set, falling back to default profiles: default
2020-04-08 16:46:06.623  INFO 14984 --- [main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:46:06 CST 2020]; root of context hierarchy
2020-04-08 16:46:07.968  INFO 14984 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:46:06 CST 2020]; root of context hierarchy
2020-04-08 16:46:08.052  INFO 14984 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-04-08 16:46:08.053  INFO 14984 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-04-08 16:46:08.101  INFO 14984 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:46:08.102  INFO 14984 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:46:08.157  INFO 14984 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:46:08.410  INFO 14984 --- [main] c.z.m.SpringBootApplicationTests         : Started SpringBootApplicationTests in 2.123 seconds (JVM running for 2.649)
2020-04-08 16:46:08.449 DEBUG 14984 --- [main] c.z.m.SpringBootApplicationTests         : 这是debug日志...
2020-04-08 16:46:08.450  INFO 14984 --- [main] c.z.m.SpringBootApplicationTests         : 这是info日志...
2020-04-08 16:46:08.450  WARN 14984 --- [main] c.z.m.SpringBootApplicationTests         : 这是warn日志...
2020-04-08 16:46:08.451 ERROR 14984 --- [main] c.z.m.SpringBootApplicationTests         : 这是error日志...
2020-04-08 16:46:08.460  INFO 14984 --- [Thread-1] o.s.w.c.s.GenericWebApplicationContext   : Closing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:46:06 CST 2020]; root of context hierarchy
2020-04-08 21:07:59.766  INFO 15932 --- [main] c.z.m.SpringBootApplicationTests         : Starting SpringBootApplicationTests on zhangkun0400 with PID 15932 (started by zhangkun04 in D:\eclipseworkspace\springboot_002)
2020-04-08 21:07:59.768 DEBUG 15932 --- [main] c.z.m.SpringBootApplicationTests         : Running with Spring Boot v1.4.3.RELEASE, Spring v4.3.5.RELEASE
2020-04-08 21:07:59.769  INFO 15932 --- [main] c.z.m.SpringBootApplicationTests         : No active profile set, falling back to default profiles: default
2020-04-08 21:07:59.814  INFO 15932 --- [main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.s[email protected]5d0a1059: startup date [Wed Apr 08 21:07:59 CST 2020]; root of context hierarchy
2020-04-08 21:08:01.360  INFO 15932 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.s[email protected]5d0a1059: startup date [Wed Apr 08 21:07:59 CST 2020]; root of context hierarchy
2020-04-08 21:08:01.418  INFO 15932 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-04-08 21:08:01.420  INFO 15932 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-04-08 21:08:01.447  INFO 15932 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 21:08:01.448  INFO 15932 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 21:08:01.487  INFO 15932 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 21:08:01.639  INFO 15932 --- [main] c.z.m.SpringBootApplicationTests         : Started SpringBootApplicationTests in 2.275 seconds (JVM running for 3.022)
2020-04-08 21:08:01.661 DEBUG 15932 --- [main] c.z.m.SpringBootApplicationTests         : 这是debug日志...
2020-04-08 21:08:01.661  INFO 15932 --- [main] c.z.m.SpringBootApplicationTests         : 这是info日志...
2020-04-08 21:08:01.661  WARN 15932 --- [main] c.z.m.SpringBootApplicationTests         : 这是warn日志...
2020-04-08 21:08:01.661 ERROR 15932 --- [main] c.z.m.SpringBootApplicationTests         : 这是error日志...
2020-04-08 21:08:01.665  INFO 15932 --- [Thread-1] o.s.w.c.s.GenericWebApplicationContext   : Closing org.s[email protected]5d0a1059: startup date [Wed Apr 08 21:07:59 CST 2020]; root of context hierarchy

二.如果我们配置的是loggin.path,如下:

logging.path=/spring/log

则会在我们项目的磁盘下创建一个log文件,

spring.log日志文件内容如下:

2020-04-08 16:51:48.278  INFO 16368 --- [main] c.z.m.SpringBootApplicationTests         : Starting SpringBootApplicationTests on zhangkun0400 with PID 16368 (started by zhangkun04 in D:\eclipseworkspace\springboot_002)
2020-04-08 16:51:48.279 DEBUG 16368 --- [main] c.z.m.SpringBootApplicationTests         : Running with Spring Boot v1.4.3.RELEASE, Spring v4.3.5.RELEASE
2020-04-08 16:51:48.280  INFO 16368 --- [main] c.z.m.SpringBootApplicationTests         : No active profile set, falling back to default profiles: default
2020-04-08 16:51:48.323  INFO 16368 --- [main] o.s.w.c.s.GenericWebApplicationContext   : Refreshing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:51:48 CST 2020]; root of context hierarchy
2020-04-08 16:51:51.273  INFO 16368 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:51:48 CST 2020]; root of context hierarchy
2020-04-08 16:51:51.402  INFO 16368 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-04-08 16:51:51.404  INFO 16368 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-04-08 16:51:51.469  INFO 16368 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:51:51.470  INFO 16368 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:51:51.560  INFO 16368 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-04-08 16:51:51.936  INFO 16368 --- [main] c.z.m.SpringBootApplicationTests         : Started SpringBootApplicationTests in 4.249 seconds (JVM running for 5.196)
2020-04-08 16:51:51.996 DEBUG 16368 --- [main] c.z.m.SpringBootApplicationTests         : 这是debug日志...
2020-04-08 16:51:51.997  INFO 16368 --- [main] c.z.m.SpringBootApplicationTests         : 这是info日志...
2020-04-08 16:51:51.998  WARN 16368 --- [main] c.z.m.SpringBootApplicationTests         : 这是warn日志...
2020-04-08 16:51:51.999 ERROR 16368 --- [main] c.z.m.SpringBootApplicationTests         : 这是error日志...
2020-04-08 16:51:52.038  INFO 16368 --- [Thread-1] o.s.w.c.s.GenericWebApplicationContext   : Closing org.s[email protected]5d0a1059: startup date [Wed Apr 08 16:51:48 CST 2020]; root of context hierarchy

参考网址如下:https://blog.csdn.net/qq_37859539/article/details/82464745

原文地址:https://www.cnblogs.com/longlyseul/p/12663155.html

时间: 2024-10-07 05:09:32

SpringBoot(八)----SpringBoot配置日志文件的相关文章

配置日志文件

org.apache.log4j.Logger详解 1.概述 1.1. 背景 在应用程序中添加日志记录总的来说基于三个目的:监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作:跟踪代码运行时轨迹,作为日后审计的依据:担当集成开发环境中的调试器的作用,向文件或控制台打印代码的调试信息. 最普通的做法就是在代码中嵌入许多的打印语句,这些打印语句可以输出到控制台或文件中,比较好的做法就是构造一个日志操作类来封装此类操作,而不是让一系列的打印语句充斥了代码的主体. http://l

Log4j中配置日志文件相对路径

log4j.appender.file.File=${catalina.home}/logs/yctxkj_blog.log ${catalina.home} 是tomcat的catalinjia脚本的启动路径,这样配置后日志会写入到tomcat的logs目录下. windows测试通过,linux下理论上也在tomcat的logs目录下.

SpringBoot(八) -- SpringBoot与Docker

一.Docker简介 Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源.Docker可以让开发者打包他们的应用以及依赖到一个轻量级,可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化. 容器完全使用沙箱机制,相互之间不会有任何接口,更重要的是容器性能开销极低.Docker支持将软件编译成一个镜像;然后在镜像中各种软件做好布置,将镜像发布出去,其他使用者可以直接使用这个镜像.运行中的这个镜像称为容器,容器启动时非常快速的. 二.Docker核心

日志文件的配置----【logback-spring.xml】

一.引入相关包 <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifa

【.net 深呼吸】写入日志文件

记录日志,一方面可以把日志写入系统的日志存储中,可在“事件查看器”窗口中查看:如果不喜欢写到系统的日志文件中,也可以写到自己定义的文件中. 其实,日志文件就是文本文件,可能有朋友会想到用写入文本文件的方式来写日志.当然,这样做也是可以的,不过,.NET 类型库提供了两个专用记录信息的类. Debug 类大家都很熟悉,就是可以在VS的“输出”窗口写入调试信息,另外,有一个跟Debug很像的类——Trace.Debug通常只会在调试版本中使用,Trace既可以在调试版本中用,也可以用于发布(Rele

php添加日志文件

记录一下. 有时候写测试代码的时候,不习惯直接在屏幕上输出反馈,那么可以配置日志文件,把需要输出的内容追加到日志文件里面,就很方便. Php自带日志系统,可以参考网上的博客配置. 我要说的是,如果你的web服务器下如果有多个应用,全部都追加日志到一个文件的话,那,emmm... 解决办法: 在每一个应用创建一个专门存放日志的文件夹,在应用程序里面把内容输出追加到该文件就可以了.这个方法是很容易就能想到的.比较简单. 首先如上图,我的应用名字叫做wx,那么我就在里面建了一个logs文件夹,里面有两

SpringBoot(八)配置logback日志

Logback是由log4j创始人设计的又一个开源日志组件.logback当前分成三个模块:logback-core,logback- classic和logback-access.logback-core是其它两个模块的基础模块.logback-classic是log4j的一个 改良版本.此外logback-classic完整实现SLF4J API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging.logback-access访问模块与Servlet容器集成提供通过Ht

springboot(三)配置日志

工程代码:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo 1.添加pom.xml依赖 <!-- log4j. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </depen

linux后台启动springboot并指定日志文件名称

如果用nohup启动jar包的话,默认的日志文件就是nohup.out,那么如果启动多个jar包的话,看日志文件就麻烦了,因为他们都会写入到nohup.out文件中. 所以我们来指定一下不同jar包的日志文件名: [[email protected] ~]$ mkdir log [[email protected] ~]$ nohup java -jar dianyixia-0.0.1-SNAPSHOT.jar > log/dianyixia.log & [1] 5861 [[email p