Spring-boot-demo学习记录(五)-spring-boot 日志持久化之AOP方式+Logback方式

 

 

 


前言

此系列博客是个人在学习springBoot的学习笔记,算是一个记录吧,一方面记录学习的内容,一方面记录学习中犯下的错误。学习springBoot选择的是GitHub上一个比较著名的项目,链接如下https://github.com/xkcoding/spring-boot-demo.git。这是一个从易到难的项目,目标:完成本地实现。技术差,文笔差,学习能力差,啥都差,欢迎指正,拒绝喷人


 

一、要实现的demo?

  本demo是将原项目的两个demo合成为一个demo,因为一般情况下AOP方式和logback方式侧重点不同。aop用来记录敏感操作,logback用来本地记录日志文件,记录系统运行日志。所以这里放一起了。本demo演示了如何使用 logback 记录程序运行过程中的日志,以及如何配置 logback,可以同时生成控制台日志和文件日志记录,文件日志以日期和大小进行拆分生成,以及如何使用 aop 切面对请求进行日志记录,并且记录 UserAgent 信息。注意事项

1.默认情况下,SpringBoot 采用logback来记录日志,并输出 INFO 级别日志到控制台spring-boot-stater的依赖中包含了logback,无需导包

2.logback-spring.xml 使用这个文件名放到resource下面无需其他配置,springboot会自动找到这个日志配置

3.log标红除非你有安装lombok,不影响调试

二、实现步骤

1.新建模块

父级依赖最外层pom.xml文件:

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xkcoding</groupId>
    <artifactId>spring-boot-learning-demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
 <!--   子模块-->
    <modules>
        <module>spring-boot-demo-helloworld</module>
        <module>spring-boot-demo-properties</module>
        <module>spring-boot-demo-actuator</module>
        <module>spring-boot-demo-admin</module>
        <module>spring-boot-demo-log</module>
        <!--        以后才会用先注释掉-->
        <!--
        <module>spring-boot-demo-admin</module>
        <module>spring-boot-demo-logback</module>
        <module>spring-boot-demo-log-aop</module>
        <module>spring-boot-demo-exception-handler</module>
        <module>spring-boot-demo-template-freemarker</module>
        <module>spring-boot-demo-template-thymeleaf</module>
        <module>spring-boot-demo-template-beetl</module>
        <module>spring-boot-demo-template-enjoy</module>
        <module>spring-boot-demo-orm-jdbctemplate</module>
        <module>spring-boot-demo-orm-jpa</module>
        <module>spring-boot-demo-orm-mybatis</module>
        <module>spring-boot-demo-orm-mybatis-mapper-page</module>
        <module>spring-boot-demo-orm-mybatis-plus</module>
        <module>spring-boot-demo-orm-beetlsql</module>
        <module>spring-boot-demo-upload</module>
        <module>spring-boot-demo-cache-redis</module>
        <module>spring-boot-demo-cache-ehcache</module>
        <module>spring-boot-demo-email</module>
        <module>spring-boot-demo-task</module>
        <module>spring-boot-demo-task-quartz</module>
        <module>spring-boot-demo-task-xxl-job</module>
        <module>spring-boot-demo-swagger</module>
        <module>spring-boot-demo-swagger-beauty</module>
        <module>spring-boot-demo-rbac-security</module>
        <module>spring-boot-demo-rbac-shiro</module>
        <module>spring-boot-demo-session</module>
        <module>spring-boot-demo-oauth</module>
        <module>spring-boot-demo-social</module>
        <module>spring-boot-demo-zookeeper</module>
        <module>spring-boot-demo-mq-rabbitmq</module>
        <module>spring-boot-demo-mq-rocketmq</module>
        <module>spring-boot-demo-mq-kafka</module>
        <module>spring-boot-demo-websocket</module>
        <module>spring-boot-demo-websocket-socketio</module>
        <module>spring-boot-demo-ureport2</module>
        <module>spring-boot-demo-uflo</module>
        <module>spring-boot-demo-urule</module>
        <module>spring-boot-demo-activiti</module>
        <module>spring-boot-demo-async</module>
        <module>spring-boot-demo-dubbo</module>
        <module>spring-boot-demo-war</module>
        <module>spring-boot-demo-elasticsearch</module>
        <module>spring-boot-d
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值