提交 ce51f434 编写于 作者: 武汉红喜's avatar 武汉红喜

logback-spring.xml

上级 923376c0
......@@ -16,6 +16,7 @@
<modules>
<module>whatsmars-boot-sample-aop</module>
<module>whatsmars-boot-sample-session</module>
<module>whatsmars-boot-sample-logback</module>
</modules>
<!--<properties>
......@@ -34,6 +35,15 @@
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......
......@@ -13,17 +13,10 @@
<name>${project.artifactId}</name>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
......
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>whatsmars-spring-boot-samples</artifactId>
<groupId>org.hongxi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-boot-sample-logback</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.hongxi.whatsmars.boot.sample.logback;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleLogbackApplication {
private static final Logger logger = LoggerFactory
.getLogger(SampleLogbackApplication.class);
@PostConstruct
public void logSomething() {
logger.debug("Sample Debug Message");
logger.trace("Sample Trace Message");
}
public static void main(String[] args) {
SpringApplication.run(SampleLogbackApplication.class, args).close();
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="sample.logback" level="DEBUG" />
<springProfile name="staging">
<logger name="sample.logback" level="TRACE" />
</springProfile>
</configuration>
\ No newline at end of file
package org.hongxi.whatsmars.boot.sample.logback;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.test.rule.OutputCapture;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
public class SampleLogbackApplicationTests {
@Rule
public OutputCapture outputCapture = new OutputCapture();
@Test
public void testLoadedCustomLogbackConfig() throws Exception {
SampleLogbackApplication.main(new String[0]);
this.outputCapture.expect(containsString("Sample Debug Message"));
this.outputCapture.expect(not(containsString("Sample Trace Message")));
}
@Test
public void testProfile() throws Exception {
SampleLogbackApplication
.main(new String[] { "--spring.profiles.active=staging" });
this.outputCapture.expect(containsString("Sample Debug Message"));
this.outputCapture.expect(containsString("Sample Trace Message"));
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="whatsmars-sharding-jdbc" />
<property name="log.context.name" value="whatsmars-cloud-zuul" />
<property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册