1. Firstly, remove springBoot’s built-in logging logs because they contain too much content.Note: not culling will conflict with subsequent packages

dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> // Logging <exclusion> <groupId> org.springFramework. boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>Copy the code

After culling and starting the project, you can find console output that is missing logs and has no information such as port numbers2. Add log dependencies

<! Slf4j </groupId> <artifactId> slf4J-API </artifactId> <version>1.7.21</version>  </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> The < version > 1.7.21 < / version > < / dependency >Copy the code

rendering

3. Compile the relevant configuration file log4j.properties

log4j.rootLogger=DEBUG,stdout,file log4j.additivity.org.apache=true log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.threshold=INFO log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-5p %c{1}:%L  - %m%n log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH-mm log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}::%L - %m%n log4j.appender.file.Threshold=INFO log4j.appender.file.append=true log4j.appender.file.File=/workspaces/logs/foodie-api/mylog.logCopy the code

rendering4. Use in projectsNote that Logger is under the org.slf4J package.