From abb1780eab861ba6513162612223ad2871e56634 Mon Sep 17 00:00:00 2001
From: "Yangkai.Shen" <237497819@qq.com>
Date: Sun, 30 Sep 2018 23:26:01 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20spring-boot-demo-logback=20?=
=?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
spring-boot-demo-logback/.gitignore | 25 +++
spring-boot-demo-logback/README.md | 184 ++++++++++++++++++
spring-boot-demo-logback/pom.xml | 55 ++++++
.../SpringBootDemoLogbackApplication.java | 40 ++++
.../src/main/resources/application.yml | 4 +
.../src/main/resources/logback-spring.xml | 77 ++++++++
...SpringBootDemoLogbackApplicationTests.java | 16 ++
7 files changed, 401 insertions(+)
create mode 100644 spring-boot-demo-logback/.gitignore
create mode 100644 spring-boot-demo-logback/README.md
create mode 100644 spring-boot-demo-logback/pom.xml
create mode 100644 spring-boot-demo-logback/src/main/java/com/xkcoding/logback/SpringBootDemoLogbackApplication.java
create mode 100644 spring-boot-demo-logback/src/main/resources/application.yml
create mode 100644 spring-boot-demo-logback/src/main/resources/logback-spring.xml
create mode 100644 spring-boot-demo-logback/src/test/java/com/xkcoding/logback/SpringBootDemoLogbackApplicationTests.java
diff --git a/spring-boot-demo-logback/.gitignore b/spring-boot-demo-logback/.gitignore
new file mode 100644
index 0000000..82eca33
--- /dev/null
+++ b/spring-boot-demo-logback/.gitignore
@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
\ No newline at end of file
diff --git a/spring-boot-demo-logback/README.md b/spring-boot-demo-logback/README.md
new file mode 100644
index 0000000..d5d0e6b
--- /dev/null
+++ b/spring-boot-demo-logback/README.md
@@ -0,0 +1,184 @@
+# spring-boot-demo-logback
+
+> 此 demo 主要演示了如何使用 logback 记录程序运行过程中的日志,以及如何配置 logback,可以同时生成控制台日志和文件日志记录,文件日志以日期和大小进行拆分生成。
+
+## pom.xml
+
+```xml
+
+
+ * 启动类 + *
+ * + * @package: com.xkcoding.logback + * @description: 启动类 + * @author: yangkai.shen + * @date: Created in 2018/9/30 11:16 PM + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@SpringBootApplication +@Slf4j +public class SpringBootDemoLogbackApplication { + + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoLogbackApplication.class, args); + int length = context.getBeanDefinitionNames().length; + log.trace("Spring boot启动初始化了 {} 个 Bean", length); + log.debug("Spring boot启动初始化了 {} 个 Bean", length); + log.info("Spring boot启动初始化了 {} 个 Bean", length); + log.warn("Spring boot启动初始化了 {} 个 Bean", length); + log.error("Spring boot启动初始化了 {} 个 Bean", length); + try { + int i = 0; + int j = 1 / i; + } catch (Exception e) { + log.error("【SpringBootDemoLogbackApplication】启动异常:", e); + } + } +} +``` + +## logback-spring.xml + +```xml + ++ * 启动类 + *
+ * + * @package: com.xkcoding.logback + * @description: 启动类 + * @author: yangkai.shen + * @date: Created in 2018/9/30 11:16 PM + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@SpringBootApplication +@Slf4j +public class SpringBootDemoLogbackApplication { + + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoLogbackApplication.class, args); + int length = context.getBeanDefinitionNames().length; + log.trace("Spring boot启动初始化了 {} 个 Bean", length); + log.debug("Spring boot启动初始化了 {} 个 Bean", length); + log.info("Spring boot启动初始化了 {} 个 Bean", length); + log.warn("Spring boot启动初始化了 {} 个 Bean", length); + log.error("Spring boot启动初始化了 {} 个 Bean", length); + try { + int i = 0; + int j = 1 / i; + } catch (Exception e) { + log.error("【SpringBootDemoLogbackApplication】启动异常:", e); + } + } +} diff --git a/spring-boot-demo-logback/src/main/resources/application.yml b/spring-boot-demo-logback/src/main/resources/application.yml new file mode 100644 index 0000000..af5002c --- /dev/null +++ b/spring-boot-demo-logback/src/main/resources/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 + servlet: + context-path: /demo diff --git a/spring-boot-demo-logback/src/main/resources/logback-spring.xml b/spring-boot-demo-logback/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..2c43a56 --- /dev/null +++ b/spring-boot-demo-logback/src/main/resources/logback-spring.xml @@ -0,0 +1,77 @@ + +