app是入口模块,依赖关系分别是app->user->common
顶层pom.xml的依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> </dependencies>
如果把log4j2.xml放在common等子模块,程序将会卡死,无错误提示,不能启动。
只有把log4j2.xml删掉,或者去除顶层pom.xml
<exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions>
都能让项目启动,但无法记录日志到文件。
请问,多模块下,该怎么做日志配置?
spring boot 默认使用logback记录日志。logback是继承与log4J的不需要额外配置.如果更改log的配置,直接在application.properties或者yml中更改配置即可