<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.14.1</version> </dependency> <?xml version="1.0" encoding="UTF-8"?> <Configuration> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="Console" /> </Root> </Loggers> </Configuration> import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggingSystem; import org.springframework.context.annotation.Bean; @SpringBootApplication public class MyApp { @Bean public LoggingSystem loggingSystem() { return LoggingSystem.get(getClass().getClassLoader()); } public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MyController { private static final Logger logger = LogManager.getLogger(MyController.class); @GetMapping("/") public String home() { logger.info("Hello, Log4j!"); return "Hello, Log4j!"; } }


上一篇:
下一篇:
切换中文