diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 9e9b35332c..18e9a27fe0 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -55,6 +55,7 @@ spring-boot-sample-jta-bitronix spring-boot-sample-jta-jndi spring-boot-sample-liquibase + spring-boot-sample-logback spring-boot-sample-metrics-dropwizard spring-boot-sample-metrics-opentsdb spring-boot-sample-metrics-redis diff --git a/spring-boot-samples/spring-boot-sample-logback/build.gradle b/spring-boot-samples/spring-boot-sample-logback/build.gradle new file mode 100644 index 0000000000..0e77a10214 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-logback/build.gradle @@ -0,0 +1,48 @@ +buildscript { + ext { + springBootVersion = '1.3.0.BUILD-SNAPSHOT' + } + repositories { + // NOTE: You should declare only repositories that you need here + mavenLocal() + mavenCentral() + maven { url "http://repo.spring.io/release" } + maven { url "http://repo.spring.io/milestone" } + maven { url "http://repo.spring.io/snapshot" } + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'spring-boot' + +jar { + baseName = 'spring-boot-sample-simple' + version = '0.0.0' +} + +run { + systemProperties = System.properties +} + +repositories { + // NOTE: You should declare only repositories that you need here + mavenLocal() + mavenCentral() + maven { url "http://repo.spring.io/release" } + maven { url "http://repo.spring.io/milestone" } + maven { url "http://repo.spring.io/snapshot" } +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter") + testCompile("org.springframework.boot:spring-boot-starter-test") +} + +task wrapper(type: Wrapper) { + gradleVersion = '1.6' +} diff --git a/spring-boot-samples/spring-boot-sample-logback/pom.xml b/spring-boot-samples/spring-boot-sample-logback/pom.xml new file mode 100644 index 0000000000..cc4de7a169 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-logback/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.3.0.BUILD-SNAPSHOT + + spring-boot-sample-logback + Spring Boot Logback Sample + Spring Boot Logback Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java b/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java new file mode 100644 index 0000000000..330f72cd11 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package 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) throws Exception { + SpringApplication.run(SampleLogbackApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml b/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..3761cc62b6 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java b/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java new file mode 100644 index 0000000000..b452efa7c4 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.logback; + +import org.junit.Rule; +import org.junit.Test; +import org.springframework.boot.test.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"))); + } + +}