diff --git a/spring-boot-demo-logback/README.md b/spring-boot-demo-logback/README.md new file mode 100644 index 0000000..f6ebcab --- /dev/null +++ b/spring-boot-demo-logback/README.md @@ -0,0 +1,122 @@ +# spring-boot-demo-logback + +依赖 [spring-boot-demo-helloworld](../spring-boot-demo-parent) + +### pom.xml + +```xml + + + 4.0.0 + + spring-boot-demo-logback + 0.0.1-SNAPSHOT + war + + spring-boot-demo-logback + Demo project for Spring Boot + + + com.xkcoding + spring-boot-demo-parent + 0.0.1-SNAPSHOT + ../spring-boot-demo-parent/pom.xml + + + + spring-boot-demo-logback + + + +``` + +### SpringBootDemoLogbackApplication.java + +```java +@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); + } + } +} +``` + +### application.yml + +```yml +server: + port: 8080 + context-path: /demo +spring: + application: + name: logback-demo +``` + +### logback-spring.xml + +```xml + + + + + + + + + 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} + + + + + + + + + ${user.dir}/logs/log/logback-demo.%d.log + + + 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n + + + + + + ERROR + ACCEPT + DENY + + + + + ${user.dir}/logs/error/logback-demo.%d.error + + + 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n + + + + + + + + + +``` \ No newline at end of file