参考页面
springProperty
// source来源于配置文件 比如applicaton.yml
<springProperty scope="context" name="LOG_FILE_NAME" source="logging.file.name"/>
// defaultValue
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>${fluentHost}</remoteHost>
...
</appender>
使用
比如文件路径: ${FILE_DIR}/${LOG_FILE_NAME}_%d{yyyy-MM-dd}_%i.log
springProfile
spring:
application:
name: springboot-logback
profiles:
active: test
<springProfile name="default">
<property name="FILE_DIR" value="c:/logs/springboot-logback-default/" />
</springProfile>
<springProfile name="test">
<property name="FILE_DIR" value="c:/logs/springboot-logback-test/" />
</springProfile>
<springProfile name="dev">
<property name="FILE_DIR" value="c:/logs/springboot-logback-dev/" />
</springProfile>
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name="!production">
<!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>
Log Groups
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
logging.level.tomcat=TRACE
# 在application文件中配置
logging:
file:
name: springboot-log-group
path: c:/logs/springboot-log-group/
group:
task: com.kq.log.task
sql1: com.kq.log.dao,com.kq.log.sql
logic: com.kq.log.controller,com.kq.log.service
level:
task: debug
sql1: debug
logic: debug
Color-coded Output
# 右对齐
%clr(%5p) %5p
# 左对齐
%clr(%-5level) %-5level
Level | Color |
| Red |
| Red |
| Yellow |
| Green |
| Green |
| Green |
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
The following colors and styles are supported:
-
blue
-
cyan
-
faint
-
green
-
magenta
-
red
-
yellow
属性
Spring Environment | System Property | Comments |
| | The conversion word used when logging exceptions. |
| | Whether to clean the archive log files on startup (if LOG_FILE enabled). (Only supported with the default Logback setup.) |
| | If defined, it is used in the default log configuration. |
| | Maximum log file size (if LOG_FILE enabled). (Only supported with the default Logback setup.) |
| | Maximum number of archive log files to keep (if LOG_FILE enabled). (Only supported with the default Logback setup.) |
| | If defined, it is used in the default log configuration. |
| | Total size of log backups to be kept (if LOG_FILE enabled). (Only supported with the default Logback setup.) |
| | The log pattern to use on the console (stdout). (Only supported with the default Logback setup.) |
| | Appender pattern for log date format. (Only supported with the default Logback setup.) |
| | The log pattern to use in a file (if |
| | The format to use when rendering the log level (default |
| | Pattern for rolled-over log file names (default |
| | The current process ID (discovered if possible and when not already defined as an OS environment variable). |