我的log4j2.yml配置文件存在问题 - 以下配置不能按预期工作:
fileName: "${baseName}/logs/${project.build.finalName}.log"
filePattern: "${baseName}/logs/%d{yyyy-MM-dd}_${project.build.finalName}.log.gz"
变量$ {baseName}已在application.properties文件中声明:
baseName="d:\dev\dd"
通过build.gradle文件中的以下依赖项添加了yaml支持:
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"
当我构建项目时,我在项目根目录中有一个$ {baseName}目录。由于某些原因,值“d:\ dev \ dd”尚未分配给$ {baseName}变量。
任何想法如何处理?
答案 0 :(得分:1)
变量应该在log4j2.yml中设置为properties.property,如:
Configuration:
properties:
property:
- name: baseName
value: /home/shared/log/
- name: filename
value: sample.log
- name: pattern
value: "%d{yyyy-MM-dd HH:mm:ss} [%p] [%t] [%c] %m%n"
status: INFO
Appenders:
Console:
name: console
target: SYSTEM_OUT
PatternLayout:
pattern: "${pattern}"
RollingFile:
- name: FileAppender
fileName: "${baseName}${filename}"
filePattern: "${baseName}${filename}-%d{yyyy-MM-dd}"
PatternLayout:
pattern: "${pattern}"
Policies:
TimeBasedTriggeringPolicy: {}
Loggers:
Root:
level: INFO
AppenderRef:
- ref: console
- ref: FileAppender