1. 如何啓用日誌?html
maven依賴中添加:
spring-boot-starter-logging
spring<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency>實際開發中咱們不須要直接添加該依賴。 你會發現
spring-boot-starter
其中包含了spring-boot-starter-logging
,該依賴內容就是Spring Boot
默認的日誌框架logback。例如:spring-boot-starter-thymeleaf。
springboot此外,spring-boot-starter 核心Spring Boot starter,包括自動配置支持,日誌和YAML等。框架
2. spring boot 默認日誌maven
默認採用的日誌是slf4j+logback,其餘框架或者第三方庫會經過jul-to-slf4j,log4j-to-slf4j等橋接庫,將其日誌重定向到slf4j,進而採用logback打印輸出。spring-boot
你可能須要排除其餘框架或者第三方庫的原來使用的日誌實現(由於他們可能在他們的pom依賴中添加了編譯/打包範圍的日誌實現依賴(例如:log4j2,springboot的starter組件配置依賴時默認排除了springboot框架使用的common-logging日誌框架)。日誌
3. 需不須要修改默認日誌code
不須要,強烈建議,除非有不可抗拒的緣由(不會有的,別想了)。orm
4. spring boot 如何自定義日誌配置項htm
經常使用選項:
logging.exception-conversion-word LOG_EXCEPTION_CONVERSION_WORD The conversion word used when logging exceptions. logging.file LOG_FILE If defined, it is used in the default log configuration. logging.file.max-size LOG_FILE_MAX_SIZE Maximum log file size (if LOG_FILE enabled). (Only supported with the default Logback setup.) logging.file.max-history LOG_FILE_MAX_HISTORY Maximum number of archive log files to keep (if LOG_FILE enabled). (Only supported with the default Logback setup.) logging.path LOG_PATH If defined, it is used in the default log configuration. logging.pattern.console CONSOLE_LOG_PATTERN The log pattern to use on the console (stdout). (Only supported with the default Logback setup.) logging.pattern.dateformat LOG_DATEFORMAT_PATTERN Appender pattern for log date format. (Only supported with the default Logback setup.) logging.pattern.file FILE_LOG_PATTERN The log pattern to use in a file (if LOG_FILE is enabled). (Only supported with the default Logback setup.) logging.pattern.level LOG_LEVEL_PATTERN The format to use when rendering the log level (default %5p). (Only supported with the default Logback setup.)